How to walk with AddForce without having too much force upon start

My 2D player can walk and push objects via RB.Addforce. The problem is: in order to get the player to start walking quickly, a lot of force needs to applied each FixedUpdate, so that within a frame or two he is up to maximum speed. I limit the velocity to prevent further acceleration and apply a massive drag so he stops quickly when keys are released, behaving like a traditional character that is moved with transforms. However, this means my player can push massive objects too easily when starting to walk, because I am exaggerating forces to get him moving quickly. So, I need a way to move my player with a realistic 2d fashion( from stop to full speed near instantly), using forces, so that he can interact with physics objects, without this overpowering effect. Methods like RB.MovePosition or directly setting RB.velocity create the same problem; objects are just pushed forward no matter their mass. My only solution I can think of is to start using Collision detection and manually remove forces in this situation, but I’m hoping for a more elegant solution. I’m hoping I have missed something very obvious. Any suggestions appreciated. Thanks in advance.

for better game feel I definitely recommend to manually use .velocity.
Then when you push an object, apply can offset/multiplier to the speed

I definitely second this recommendation.

And if you need the speed to change smoothly rather than all at once:

Smoothing movement between any two particular values:

https://discussions.unity.com/t/812925/5

You have currentQuantity and desiredQuantity.
- only set desiredQuantity
- the code always moves currentQuantity towards desiredQuantity
- read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: https://gist.github.com/kurtdekker/fb3c33ec6911a1d9bfcb23e9f62adac4

If you do insist on doing it with forces you will need a PD filter controller.

https://en.wikipedia.org/wiki/PID_controller

You can almost certainly do without the I part and just do the PD part. :)

Thanks for the great advice so far. My temporary solution, as bizarre as it sounds, is to set my player mass to almost zero, with a high drag. He accelerates instantly, and when he is bumped into by objects still resists as if he has normal mass due to the drag. It probably has pitfalls I havent bumped into yet, but it is doing the job of at-least appearing to simulate the physics I am looking for. It's a bandaid solution while I attend to other things, but I will definitely come back and try the PID controller...which I used to play with years ago when drones first came out. Interesting indeed.

Huh, that actually sounds kinda interesting. I hope it works well for you!

When you say that it reminded me of this great discussion of a physics character controller:

https://www.youtube.com/watch?v=qdskE8PJy6Q

Check out the car one too:

https://www.youtube.com/watch?v=CdPYlj5uZeI

Brilliant stuff.

Yep. The physics based character controller is pretty much exactly what I was looking for. Awesome , and a big thanks.

1 Like