Determining if a character is touching the ground.

jchmack

14-01-2008 18:42:33

I need to determine if a character is touching the ground so he can't just jump over and over again. I have a couple ideas on how to achieve this:

Raycast below the character: seems like this would work the best but i would prefer to not have to do a raycast every frame. I know raycasts are cheap but they still aren't free.

Change to an "in the air" state when a character jumps and change back when he touches the ground: I'm thinking that this would allow one free air jump if the character just walked off an edge. The only way to prevent this would be to raycast again which would defeat the purpose of this method.

Somebody has to have experience with something like this. All advice is greatly appreciated.

betajaen

14-01-2008 20:36:43

I used both of those in the 0.4 character code. It came out pretty well. But instead of raycasting every time, I just measured the vertical velocity of the character then started to raycast when it was alarming, then move into a fall mode if the character was above 25cm of ground.

But for both of those you need a bit of leeway for tiny falls, steps, or uneven terrain.

jchmack

17-01-2008 17:36:09

thx i got it working the way i want with a your recommended combo.

Arcanor

29-02-2008 03:49:27

jchmack: would you mind posting your code for the rest of us to see? :) It would be much appreciated!

edit: I see you've already done this in another thread:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=6413