Jump to content
  • Advertisement

Archived

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

Schmerm

The physics of walking+friction in a FPS environment

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've made a simple terrain engine and implemented collision resolution based on bounding spheres. Now, I want the player to be able to walk on the terrain. Part of my frameloop looks like this so far: 1) set acceleration to zero 2) add gravity (should walking code go here?) 3) integrate to get new position/velocity 4) detect and resolve collisions: { if bounding sphere extent is below ground, project it upwards using surface normal and the distance difference, and kill the normal component of player's velocity } 5) create view matrix from player pos/orientation and render It works perfectly in the sense that you will forever slide all over the place, since there's no friction of any kind yet. Now, to make the player walk nicely, I need to both accelerate up to a max velocity, and handle all sorts of friction. I've been playing with a few ideas (static+kinetic friction forces, or modifying velocity directly, etc.) but nothing feels quite right, or requires too many special cases and isn't elegant. I'm aiming for the kind of walking in Tribes2, where it seems that the amount of control you have isn't just dependent on the maximum static friction but also on your tangential velocity (for example, if you're moving too quickly down a slope, you'll start sliding, but if your velocity is low enough on the same slope, you still have control). At first, implementing walking seemed trivial compared to collision detection and more serious-sounding game physics issues, but for some reason the logic behind it is escaping me. Has anyone found a good simple-ish physical model for walking across terrain? [edited by - Schmerm on May 9, 2004 12:27:22 AM] [edited by - Schmerm on May 9, 2004 12:28:16 AM]

Share this post


Link to post
Share on other sites
Advertisement
What I did was every frame multiplied the player''s (walking) velocity by a friction constant:

Vel *= c_friction

Where c_friction is something between .7~.99

When they walk they have a constant acceleration in whatever direction; we really don''t need to check for a max velocity because the friction combined with the acceleration defines this for us. (don''t ask me why - I didn''t bother to work it out).

I don''t really know what to do about sliding down hills, though. I think you''d have to wait until the slope of the hill breaches a certain value, otherwise you''d be slipping and sliding whenever the ground was unlevel. I didn''t have hills (all indoors) so I really didn''t have to worry about it .

Hope that helped a little.


Yes... VB6 is here to steal your minds fps. Very slowly.
Call .optimize(you.sig)

Share this post


Link to post
Share on other sites
check if the velocity magnitude along the sliding surface is below a threshold. if it is, remove that from the player velocity.

I''d try

float vn = V * N; // impact velocity magnitude
Vector Vn = vn * N; // impact velocity
Vector Vt = V - Vn; // slide velocity

float slide_speed = Vt.Normalise(); // slide speed

slide_speed *= surface_drag; // surface drag (0.99f).

slide_speed -= static_friction_speed_threshold; // apply static friction
if (slide_speed < 0) slide_speed = -0.000001f; // small margin of error

Vt = Vt * slide_speed; // slide velocity after friction
Vn *= -Elasticity; // impact velocity after collision

V = Vn + Vt; // velocity after collision

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!