I am trying to encapsulate some physics into my collision resolution but am having the following problem:
I have a player (human) model walking around a map (imagine a 1st person shooter). It is colliding with all pollys (walls and floor) and resolving a new velocity via:
*vel -= CollidedNormal * DotProd(vel, &CollidedNormal);
Where CollidedNormal is the normal of the poly it collided with.
Gravity is added to the velocity initially to keep the player ''on the floor''. The slidding along walls is fine however when the player tries to walk up a slope of any real gradient he/she ends up slowing to a stop on the slope.
Can anyone throw some light on how I might go about fixing this so the player can slide along walls and walk up slopes??
Thanks in advance
Decrease the gravity and i can walk up slopes oki (sliding is fine also) but with a higher, more realistic gravity, i just cant walk up slopes (altho sliding down them is more realistic with a modest gravity value)
player.y-=0.3f (which would be 30 cm. in my game) then I find out if the distance between the coordinates of the player and a face is less than 1.50f, and If it is, I push the player away 1.50f along the face''s normal. This way the speed at which the player slides down a slope depends on the steepness of the slope.. Another way is, which I am using now(better for shoot em ups), is to find out if the face is a wall or a floor, for example, if the steepness of the face is more than 45 degrees it''s a wall. if its a wall I use the same method as i described before, but if its a floor I dont push the player away along the normal of the face but up vertically. This is better for shoot em ups because you won''t slow down when walking up, which is very annoying. I hope this is what youre talking about...
I tried to make my game with accurate physics like yours, and it took months, and it still isn''t right in some cases.
My game was in 2D, but the same rules apply. Gravity is applied to an object''s velocity every loop, and whenever there is a collision, it is resolved by changing the velocity in the direction normal to the colliding surface, as you said. I also change the velocity in the shear(?) direction, representing friction.
How does your player get its velocity in the first place? Whether you calculate it by friction or just by assigning it to a number, there will always be a slope too steep.
The physics here is not too complicated, but the problem for me was what I called "scraping problems". When you adjust the velocity after a collsion, the object should be sliding along the surface. But with rounding errors you might find that it''s still moving very slightly into the surface, and so you have a collision which can''t be resolved. Even having a velocity slightly away from the surface may not solve it, depending on the way you check for collisions.
If you want to handle multiple body problems, that gets more difficult again, as the simple 2-body rules will not solve them.
I can go into more detail here if you want, or you can email me. I have a lot of code (C++) which deals with moving objects and resolving collisions between them.