# Grounded or In-Air

## Recommended Posts

I'm having a problem deciding how to determine if my objects are on the ground or not. The game is a futuristic, cyberpunk, gun toting RPG. It's more about how far from the ground. I need to decrease Y velocity to simulate gravity, but I don't want to do this if an object is resting on the ground. Is there a smarter way to apply gravity? My landscape can be of any shape. So I can't just use a zero point for the ground. That means I have to intersect triangles to get the distance. A sphere shaped object's ground location should be it's bottom (position.y - Radius). But a character's bottom should be their position (just position.y, which is the space between their feet). On the other hand, if a character is flipping around in the air, his bottom should be whatever collision sphere is lowest, no? Nope. On an edge, one of his "upper spheres" could collide with a ground before his "lower spheres".
           O  <- head, which will hit first
------------\  <- midsection
|/\ <- legs, they are lowest
|
|
------------------------------
[lol] Okay, so the example is pretty lame. But this can happen as well when a character goes to step off of an edge. His stepping foot will end up being lower than the one resting on the ground. Basically, I want to avoid intersecting lines towards the ground for every collision sphere in every object. What would be the best way to figure out how far an object is from the ground? I'm looking for opinions, not facts. Thanks [smile]

##### Share on other sites
IMO, I've never seen a fps "flip" people! While that might be interesting to try, you'll run into problems like this one.

Personally, I'd be inclined to do a bounding box collision (people look like rectangular prisms to me [wink]), but this would require the y value at a given x,z point (yay! Heightmap interpolation...grr)

Oh well. Might be a neat thing to see! Post screens when you get them of people flying and swinging around in the air! [lol]

##### Share on other sites
Well, it's not a FPS. It's 3rd person. But I see what you're saying. I'm not sure how much flipping will occur, but if a character is being blasted into the air, I would really like to have them flip a bit [lol]

I was thinking about going the ragdoll route, but it is too unpredictable. You have to tweak those bone specifications for weeks + months before it looks good. And it usually still doesn't look right (Hitman, etc, they did it really well, and the character's still bounced + flipped like stuffed puppets).

When you say bounding box, you mean an entire 3D box? I already have collision spheres setup in the model, moving around with his bones, performing terrain collision checks and fixes. Right now, the whole body acts as a single unit. If one sphere collides, the whole body must move to correct the problem. I'm gonna leave it this way until I raise my math skills a bit, hehe. Later, I may try to correct limb movements to avoid collisions. But that's well above me at the moment.

The spheres on his arms + legs + feet + head prevent him from going through things, including the floor. My main problem is not knowing how to detect if the object has become air-born. I've tried turning on a status flag (GROUNDED) to true when any sphere collides with a triangle that has a normal whose y is more than 0.5 (so it's facing up). The flag is unchecked when there is any movement. The problem here is that his animations of walking are throwing his feet around, which makes the GROUNDED flag very unstable. Gravity is only applied when the object is air-born, so when his animation moves him forward, it unchecks the flag, but gravity doesn't have enough time to push him down to collide and check the flag back on immediately.

Bah, I rambled on a bit there. Hopefully someone has an idea regarding this whole gravity thing?

Thanks again [smile]

##### Share on other sites
Well, if i ever complete mine... i was hoping to make the camera's "down" be towards the gravitational pull... and also have point gravity... how cool would that be? :-D
-Dan

##### Share on other sites
Most games handle this situation by using a single 'bounding shape' fr an entire object for object<->world collisions. What kind of bounding shape depends on the game, but common shapes are bounding boxes, cylinders(good for approximating the human form), and spheres.

You only really need the more advanced kind of collision detection for things that need to look good graphically, like a spell/bullet/etc hitting a part of the body.