limiting player speed

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

Recommended Posts

Hey everyone, I have a question about how to limit a player's speed. I have implemented a simple physics system: every player has a mass, position, velocity, and net force that is being applied to them. At every frame, the player's velocity is added to its position and the player's net force divided by mass is added to its velocity. When a player wants to move, a force is applied (added to the net force) in the desired direction of movement. This is nice because it causes the player to smoothly accelerate and decelerate. However, if the player holds down a key, they will accelerate without limit. The obvious solution is to cap the player's velocity at some level, but I don't want to do this because the game will have external forces like gravity wells and explosions and I don't want the effects of these to be capped. One thing that has worked for me is to implement friction which naturally limits the player's motions if the friction force is proportional to the player's velocity. However I can't easily change how fast the player reaches their maximum velocity. One thing I can think of would be to have some variable which decreases while the movement key is being held, and then apply the movement force based on this variable. Another idea I had is more physically based: when people walk, they apply a force to move themselves periodically. My idea is to apply the movement force to the player in a periodic fashion to (hopefully) naturally limit it's speed. Any thoughts/ideas?

Share on other sites
You could make the player unable to apply force to increase his own velocity when his velocity is already higher than a certain constant. Then explosions could propel a player at any rate but movement speed would not accelerate endlessly.

Share on other sites
Quote:
 Original post by MilfredCubicleXHowever, if the player holds down a key, they will accelerate without limit. The obvious solution is to cap the player's velocity at some level, but I don't want to do this because the game will have external forces like gravity wells and explosions and I don't want the effects of these to be capped.
Then you should limit the amount of acceleration that the user can apply. I would split up user applied force and externally applied force. Then you just need to cap the amount of user applied force and recombine the two forces when you update the velocity. You may be able to split up the forces, update them separately to get 2 speeds, and then limit the user applied speed if you wish to control that variable more directly. Then combine the two speeds. Something along those lines at any rate.

Share on other sites
Quote:
 Original post by DanX2002You could make the player unable to apply force to increase his own velocity when his velocity is already higher than a certain constant. Then explosions could propel a player at any rate but movement speed would not accelerate endlessly.

I like this idea, I will give it some thought.

Quote:
Original post by nobodynews
Quote:
 Original post by MilfredCubicleXHowever, if the player holds down a key, they will accelerate without limit. The obvious solution is to cap the player's velocity at some level, but I don't want to do this because the game will have external forces like gravity wells and explosions and I don't want the effects of these to be capped.
Then you should limit the amount of acceleration that the user can apply. I would split up user applied force and externally applied force. Then you just need to cap the amount of user applied force and recombine the two forces when you update the velocity. You may be able to split up the forces, update them separately to get 2 speeds, and then limit the user applied speed if you wish to control that variable more directly. Then combine the two speeds. Something along those lines at any rate.

This is similar to a solution I have used for a while (except that I used two different velocity variables). I will think about this some more. Thanks to you both.

Share on other sites
How about going back to basics and only applying the velocity change ON KEY DOWN, which shouldn't be called again until ON KEY UP. Use key states, checking for change.

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• Forum Statistics

• Total Topics
632940
• Total Posts
3009328
• Who's Online (See full list)

There are no registered users currently online

×