Here is the setting:
- I have a ball rolling horizontally on the ground from left to right on a platform (rectangle). These two objects are associated to BEPU physics models ("Sphere" for the ball and "Box" for the platform).
- The ball jumps at a certain height with a certain speed.
Unfortunately, the ball sinks into the platform upon landing instead of properly colliding with it. Is there any way to fix this problematic issue?
Here is the how the jump mechanic work:
- In the ball's method "update ()": I apply a vertical force on the physics model ("Sphere") via the "LinearVelocity" attribute, which corresponds to the jump speed (30 in my case) until the ball reaches a certain height on the y-axis.
- Then, I apply the same negative force to bring down the ball until it collides with the platform.
To check if the ball collides with the platform I use the event: "InitialCollisionDetected".
Here is an example of how I do it (pseudo code):
Code: Select all
sphere.EventManager.InitialCollisionDetected += HandleCollision;
void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
isJump = false;
}
public void jump()
{
isJump = true;
}
public void update()
{
if(isJump)
{
if(currentHeight < jumpHeight)
{
sphere.LinearVelocity = new Vector3(sphere.LinearVelocity.X, 30, sphere.LinearVelocity.Z);
}
else
{
sphere.LinearVelocity = new Vector3(sphere.LinearVelocity.X, -30, sphere.LinearVelocity.Z);
}
}
}
Thank you for your time.