Sign in to follow this  
Meshboy

Quake PM_ClipVelocity

Recommended Posts

Hi folks! I am doing a FPS game where i have sucessful collision detection and response. I do this by only doing this: Compute collision (distance to line (only x,z)-velocity length (speed) if collision then take vector from closestPointOnLine to Player and push the player out. but i am NEVER using dot product for this. i have seen many slide plane calculations and they all use dot produt. something like: sphere_velocity -= n * (sphere_velocity.dotProduct(n)); My formula is this one: min = minimum distance player can go to against wall Ni = normal from closest_point_to_plane vs = velocity speed d = Distance to wall i am using this and it works: sphere_velocity += Ni * (min -(d+vs); Quake II and III using this formula for modifying the velocity, but my question is: can anyone explain what the dot-product is suppose to do? (both in this formula and all other sliding plane calucaltions)???? void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) { float backoff; float change; int i; backoff = DotProduct (in, normal) * overbounce; for (i=0 ; i<3 ; i++) { change = normal[i]*backoff; out[i] = in[i] - change; if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON) out[i] = 0; } }

Share this post


Link to post
Share on other sites
it's the reflection algorithm. If you have done A level physics / optics, that should be trivial.

Doing a dot-product in that context, is basically calculating the length of the 'velocity' along the normal of collision, or the projection length, provided the normal is normalised. If you want, name it the impact speed (speed being a real number, the magnitude of a velocity vector), or how hard the object hits the collision surface.


sphere_velocity -= n * (sphere_velocity.dotProduct(n));

basically 'kills' the speed, by subtracting the impact speed from the velocity vector along the normal of collision, from itself. All components of the velocity along the normal direction will be zeroed. That's a pure sliding motion.

Share this post


Link to post
Share on other sites
but then i am missing something... now if the player if face up against the wall with full speed, i just push him out the distance+the current speed. The right thing would be to take away all speed if player facing dead-a-head and some if the angle is just slightly towards the wall...

hm... the normal in this formula, is it closestPoint to the player or is it the real "normal" of the plane?

now i calculate this seperatle, check if player has collided and with what angle, and then reduce the speed depending on the angle. But this is done seperatly...

thanks for your answer man, you are always helpful and knows things 100% correct! =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this