platform game physics

Apr 27, 2010 at 5:30 AM
Edited Apr 27, 2010 at 5:34 AM

I am working on a platform game, a bit like New Super Mario Bros. Wii. I am having problems adjusting the physics of the player, especially with slopes. I am having 45 degrees slopes, and I would like the character to act as on the flat ground.

- The first thing is that the character kept on sliding down when on them. I fixed that by bringing the Velocity.X to 0 when the player made the character stopping moving. I don't know if it's the best way to do it, or if there is a way to say that I don't want it to slide.

- In one hand, when he goes up the "hill", once he reaches the top and is about to reach a flat ground, he keeps some inertia and keeps going a bit in the air before landing on the ground. I don't know how to fix this.

- In the other hand, when he is on the slope and goes into the direction (left or right) so as to go down, he is kind of flying, going much more horizontally than vertically. He is kind of making a big jump, not just going down. I tried to fix it by increasing the character's mass, but when it has such a big mass that it goes down well (or kind of), he is to heavy to go up the hill again.

for the slope, I put:
mesh.DynamicFriction = 0.2f;
mesh.Restitution = 0.0f;

for the character, I put:
box.DynamicFriction = 0.9f;
box.StaticFriction = 0.2f;
box.Restitution = 0.0f;

for the flat ground, I put:
box.DynamicFriction = 1.0f;
box.StaticFriction = 1.0f;
box.Restitution = 0.0f;

Is there a way you could help me? I don't know much about the physics elements, and don't exactly know what to change.

Thank you.
Apr 28, 2010 at 6:59 AM

Hey martox,

I haven't done much with character controls but I know that some use special "character" constraints that keep the controlling of the player from feeling so "floatie" when using dynamics for player control.  I've also seen it where they bypass regular collision response and run through a whole different way to resolve collisions that occur with the player.  I've also seen it where they modify the collisions that occur right before collision response occurs.

So some things you could try:

- To (attempt to) fix the sliding issue, you can add the VelocityContraint (or equivilent) to your player RigidBody and set the TargetVelocity every frame to the velocity you want your character moving, normally the controller direction times some factor.  The VelocityContraint attempts to match the TargetVelocity over a small timespan, so if the player isn't moving left or right the TargetVelocity would be 0,0,0 and the physics would attempt to keep the rigid body stationary.  When the user presses left or right, the VelocityConstraint, the TargetVelocity would be set to something like {+/-GamePad.GetState().LeftThumbStick.X * factor, 0, 0) and the player's rigid body would attempt to match that velocity, moving the player.

- To (attempt to) fix the inertia making the player float of tops of hills, doing what I stated above will help that as well since the TargetVelocity's Y-component is zero, essentially trying to cancel out any upwards velocity.

- The VelocityConstraint will help with the going down slopes as well, but you could add a bit of downward velocity to the TargetVelocity when going down slopes to help a bit more.  Cast a ray down from the players feet and if the intersection's normal suggests a downward slope, add a bit of downward velocity to the TargetVelocity.

I'm, of course, leaving a quite a bit out.  Such as taking into account if the player is jumping, not on the ground, etc.  I hope this helps get you started.  I'm sure others may have better approaches, but I've done it this way (using VelocityConstraint) and it worked out really well with this physics framework.  Good luck!



Apr 29, 2010 at 5:13 AM
Thank you for your help!

I also need to see, with the ray, if the gravity has to make the character go down. The Velocity.Y cancels gravity. I need to detect the distance between the character and the 1rst thing under it.

Could you help me with the ray casting? I don't see how to do the intersection's normal :s.

Thank you again :p
May 1, 2010 at 8:05 AM

You can use use the PhysicsComponent.CollisionSystem.IntersectsWith method to cast a CollisionRay from the feet and pointing downwards.  If you have the CollsionMesh referenced, you can use its IntersectsWith method as well.

The results of the IntesectsWith call returns the normal of the intersection.  Use this and the direction your player is moving (normalized Velocity maybe) to determine if a downward force is necessary.  This force can be calculated similarly to how the PointToPointConstraint works or just by trial and error.

...something like that.

Jul 7, 2010 at 4:58 AM


i m working on the same project as martox.

I m trying to make some moving ground and i want that all the model on this "platform" follow the movement, but i need the physique on this platform remain the same as on the rest of the ground.

Do you think about any easy way to do it ?

Jul 10, 2010 at 4:42 AM

That is a good question.  You could use a constraint and enable/disable it based on whether the player was intersecting with the platform (and nothing else probably) and it's tangent velocity was under a certain threshold.  The PointToPointConstraint might work but orientation won't match if the platform's orientation changes as it moves.

Oct 21, 2010 at 12:04 PM


thanks for your help so far.

I have an other issue : when my main mesh character collide with another one with an high velocity, this model go "through" it and then move to go "out" of the mesh (i m not sure to be clear :p).

This can be useful in some case but i don't want it, is there any way to make the model strictly respect the collision ?

Oct 25, 2010 at 4:08 AM

Unfortunately, the current version of collection detection in Oops! is descrete, meaning it only checks collisions at each descrete timestep and not the time in between (i.e, continuous collision detection).  Decreasing the target time step helps but may make the simulation take up too much time per frame.  if the high velocity item is small enough, you can check time in between with collision ray intersections and creating a Collision at the point of impact.