Detecting if an object is on the ground

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
LorgonJortle
Posts: 2
Joined: Fri Feb 12, 2010 1:43 am

Detecting if an object is on the ground

Post by LorgonJortle »

Hi,

I've a triangle mesh of my terrain, and a sphere as the player.
I only want the player to jump when it's on the "ground". How would one detect for that?

Also, I've just been adding to the Y axis of linear velocity for moving, but it's not acting properly.
It's a ball, and when I apply speed to any direction of the linear velocity, the ball takes a while to get rolling.
By this I mean that it moves as soon as I hit the key, but the ball doesn't spin as though it's rolling for a bit.
It also does this when changing directions.

Thanks,

BEPU has been wonderful so far

(And the video about the company was great, heh)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Detecting if an object is on the ground

Post by Norbo »

I only want the player to jump when it's on the "ground". How would one detect for that?
One option would be to examine the sphere's collisionPairs list. In each collision pair, there is a list of contacts. If there is more than zero contacts for a collision pair, it means that the sphere is currently colliding with that other object. This doesn't necessarily mean the sphere is on the ground (the sphere could be hitting its head, so to speak), but you can check the contacts' position and normal to narrow it down.

For example, by taking the dot product of the normal with the up vector (equivalent to just looking at the normal's Y component), you can determine how 'up' it is. You can convert the absolute value of Y into an angle here using Math.Acos if you'd like. Once it is determined that the surface normal is an acceptable support, you can check to see if the contact's position is lower than the sphere's position. The reason for this check is that the above angle check could 'accept' a contact's normal whose position is actually above the sphere's position. If these two conditions are met, you can consider the sphere to be grounded.

Another option would be to raycast down from the sphere's position against the opposing entities defined by the collision pairs. You wouldn't need to do the contact position check, just a normal check to see if the ground is not too sloped for a jump. This is similar to what the SimpleCharacterController does in the BEPUphysicsDemos source.
it moves as soon as I hit the key, but the ball doesn't spin as though it's rolling for a bit.
When only linear velocity is changed, friction is responsible for getting the sphere to start rolling. You could increase friction so that it doesn't slide, or you could apply an appropriate angular velocity along with your linear velocity.
(And the video about the company was great, heh)
:)
LorgonJortle
Posts: 2
Joined: Fri Feb 12, 2010 1:43 am

Re: Detecting if an object is on the ground

Post by LorgonJortle »

Excellent, thanks! This is a great engine. :-)
Post Reply