2
\$\begingroup\$

In my game I have an quite irregular terrain at the bottom and a round ball which can be controlled by the keyboard. Is there any way to check, if the ball is currently on the terrain? This is very important to know because the ball should only be able to be controlled when it is on the ground.

I tried to use the OnCollision event of the ball body, but it only gets fired on the first occurrence.... For my problem a continuous type of collision-detection is needed.

\$\endgroup\$
3
  • \$\begingroup\$ I'm not familiar with Farseer Physics but i assume simple raycast from the center of ball to the ground should do the trick. At least, this is how people doing it with Bullet Physics. Do the raycast and then check if distance from ball's center to the collision point is equal to the radius of the ball. Make sure that your ray doesn't hitting the ball itself. \$\endgroup\$
    – Ocelot
    Jul 22, 2015 at 11:10
  • \$\begingroup\$ @Ocelot Wouldn't that be like writing a second collison detection? It shouldn't be very CPU-intensive too.. \$\endgroup\$ Jul 22, 2015 at 11:59
  • \$\begingroup\$ As far as I know, properly implemented raycasts are pretty fast. \$\endgroup\$
    – Ocelot
    Jul 22, 2015 at 12:06

4 Answers 4

2
\$\begingroup\$

try OnSeparation.

Pseudo c# code:

private void OnSeparation(....
{
 landed=false;
}
private void OnCollision(....
{
 landed=true;
}
\$\endgroup\$
0
\$\begingroup\$

You could make a trigger at the bottom of the ball and then check if the floor is in this trigger.

\$\endgroup\$
1
  • \$\begingroup\$ Box2D calls them sensors. \$\endgroup\$ Jul 29, 2015 at 17:12
0
\$\begingroup\$

If there's gravity applied to your object you could check if the Y velocity==0 after you've done your collisions. It's maybe a bit fake it if you can't make it but in most situations it should work

\$\endgroup\$
0
\$\begingroup\$

I'm unfamiliar with Farseer, however in my own physics engine I handle this by getting an array of collisions which occurred in a given time-step and using the result of the Dot Product of the collision normal with the positive Y axis to see if any collision surface is within a certain angle of being parallel to the floor.

Raycasting is probably a better bet (especially if you are expecting many simultaneous collisions- the overhead from a check like this might be too much). Just putting an alternative out there- if this is possible with Farseer.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .