This topic is now archived and is closed to further replies.


Modelling Sliding as continuous collisions

Recommended Posts

I am trying to create a very simplistic physics model that only takes into account an object''s thrust, gravity and the ground. The gravity and thrust are expressed as vectors, and every frame I basically just add the two together (the thrust is the direction the player wants to take). Every frame, I add these to the Delta of the player and then add the delta the player position. So, if you thrust forwards for a while you end up going very fast, then if you turn around and thrust the other way you slow down (and eventually start accelerating in the opposite direction). The problem is with the ground. If the object is falling onto the ground, I can get the normal of the ground at the point of impact and reflect the delta around that normal, and that works fine - looks like a perfectly elastic collision, which is great. However, if you are sliding along the ground then there is theoretically a constant impact with the ground (because gravity will always be trying to pull you into the ground while the ground rejects that action), and this is causing me problems because the object jitters and occassionally freaks. I want to try and keep the model as simple as possible, which is why I want to use a collision for sliding behaviour - I don''t have to use seperate code paths for different movement methods. Is this possible and I''m just missing something pretty obvious, or should I abandon it and do the seperate code path route? p.s. I figure that if I make the collisions inelastic later on and get this working, it should neatly solve/approximate friction too.

Share this post

Link to post
Share on other sites
oliii    2196
you''ve got to reflect the velocity and cancel the force (thrust + gravity) along the ground normal.

F = Thrust + Gravity;
V += F;

float elasticity = 0.2f;
float friction = 0.3f;

if (collide_with_ground)
Vnorm = (V * Nground) * Nground;
Vplane = V - Vnorm;
V = Vplane * (1.0f - friction) - Vnorm * (1.0f + elasticity);

F -= (F * Nground) * Nground; // remove the force along the ground to stop the object jittering.


that way, you won''t have an extra force that keep pushing your object down to the ground, no matter how hard you push down.

Share this post

Link to post
Share on other sites