How to check if body is "on the ground" ?

Eldritch

07-04-2007 22:35:11

I experimented a bit with a jumping character using a Newton body, but quickly fell into thought about how to actually check if the Newton body is touching the ground or not. This would be an imperative check since as it is now, I can jump while in the air ;)

walaber

08-04-2007 02:07:44

option 1: keep a flag as to whether the player body is in contact with the ground body, and update that flag in the collision callback

option 2: perform a raycast pointing down to just below the player's feet to see if there is anything there!

Eldritch

08-04-2007 08:29:18

option 1: keep a flag as to whether the player body is in contact with the ground body, and update that flag in the collision callback

This sounds like a less expensive procedure, though I do not know how to exactly "update" that flag. Having to time it would be an awkard way.

Eldritch

13-04-2007 16:40:05

option 2: perform a raycast pointing down to just below the player's feet to see if there is anything there!

How to perform a raycast? Here is what I did (using MogreNewt):


public bool IsOnGround()
{
Vector3 retNorm;
int retColID;

float ret = MogreNewt.CollisionTool.CollisionRayCast
(
m_refPhysBody.getCollision(),
Vector3.ZERO,
Vector3.NEGATIVE_UNIT_Z,
out retNorm,
out retColID
);

return (ret < 1);
}


It always returns false..

oddrose

16-07-2007 17:00:11

option 1: keep a flag as to whether the player body is in contact with the ground body, and update that flag in the collision callback

This sounds like a less expensive procedure, though I do not know how to exactly "update" that flag. Having to time it would be an awkard way.



I would like a nice tutorial on that too...

oddrose

17-07-2007 15:51:50

okay...sorry for bump, but since this is the latest post on the forum, no harm done...i guess


Okay...so i did like this:

class CollisionHandler : public OgreNewt::ContactCallback {

public:

int userProcess() {

//whatever

return 1;
}
}


and I assigned an instance of that class as callback to the materialpair that is between my player and the world.

It works great so far and I can define the functions as I like...

was this what you meant Walaber?

walaber

17-07-2007 19:41:13

when doing a raycast, you need to give it a START and END point, in World-space. Newton will draw a line between START and END, and let you know if that line collides with any rigid bodies.

so for a ground check, it might be something like
START = player's position in world space
END = a short distance below the player's feet in world space.

then you would check if the ray hit any rigid bodies OTHER THAN the player's body, and if so, it's standing on something.