- Home /
How to I put a speed limit on my character's movement?
Im currently using rb.addforce method and my character keeps building up speed without having any limits, does anyone know how to put a speed limit? Thanks in advance
You can add drag to your rigidbody, to prevent it from accelerating further, or you could get the current velocity and stop adding force if the current velocity on the axis youre accelerating on is greater than maxspeed
How do I do that? Firstly, what does drag do? and how do I had a max speed limit? For my movement I did this, rb.addforce(rb.transform.forward walkspeed time.deltatime), something like that, so if I want to put a speed limit how do I do that?
Answer by IceShadows21 · Jul 28, 2020 at 11:08 AM
If you want to put a speed limit, maybe rb.addforce is not the best method because if you are using it in the Update(), it keeps adding force each frame.
Take a look at this : velocity documentation
$$anonymous$$y old movement system was based on this line of code: rb.velocity = new vector(x walk speed, y, z walk speed) this resulted in a lot of issues like my character not being pushed down slopes and there was no line of code that helped me in building up speed over time. @IceShadows21
You can use Character Controller too. This is useful for many problem like slopes, ...
Here is the documentation : link text
and here is a useful video about player movement : link text
Another solution is to use '$$anonymous$$athf.Clamp()'. You can, for example, use this on the velocity of your rigidbody like that :
rb.velocity = $$anonymous$$athf.Clamp(rb.velocity, 0, 10f);
Here is the documentation : link text
I hope it will help you
Thanks for the help, but by clamping what are we basically doing?, im trying to understand how to make games so my bad if im frustrating @IceShadows21