- Home /
How to reach a specific max speed with AddForce() ?
Hello,
Context : 3D, top view, moving a cube, using gravity.
My end goal is to create car movement with this cube (and whithout wheels).
To move the cube, i am using AddForce() and AddTorque().
if(maxSpeed < 50)
rigid.AddForce(direction * acceleration * goForward);
acceleration
variable is a fixed value and goForward
is an integer equal to 1 or -1.
I would like to have my cube accelerating slowly to reach the maxSpeed
but the AddForce()
push the cube to a speed (on which i have no control) but is unable to reach the desired maxSpeed
.
Even using ForceMode.Acceleration
don't work.
How can i do it without using a higher acceleration
?
Thanks.
Answer by Captain_Pineapple · May 20, 2018 at 10:30 PM
Hey there,
first up you want to multiply your added force by Time.deltaTime.
With that you scale the force applied according to the current "framerate". Otherwise you might have different behaviour at inconsistent framerates.
Secondly your problem might be that your rigibody has a "drag"-value. This drag value resembles some kind of combined simulation of effects like air resistance that will, in the end, let your body slow down a bit.
If your force is too small it might be enough to acutally counter the accelleration force.
Also you write that you want to create some kind of car. How do you handle the friction towards the ground? And why don't you want to use wheel collider?
I use AddForce() in FixedUpdate(() so it is not required to use Time.deltaTime from what i understand. But i tried to add it and tweaked the value. And there is no difference.
About the drag, apprently, with a low drag, i can reach the desired maxSpeed as you said and i have to increase the mass in order to get a slow acceleration like I want. But, by doing this, when i am turning at high speed, the car/cube slip too much on the side because of the low drag. And I don't want that.
Also, why the Force$$anonymous$$ode.Acceleration don't work?
One way i could do to prevent this is to give a growing acceleration and manage only this increase rate to reach the maxSpeed. So acceleration will not be a fixed value. But I heard that it will mess with the AddForce() values and may create weird behaviour on collision.
About the wheels, i said it's going to be a car but not an usual car. Think of it like a car floating on top of the ground but very close to it. Also, the game will be top down so you will not be able to see the wheels. And in my $$anonymous$$d, if you use wheels for adherence, why I can't use the bottom of the cube ?
Your answer
Follow this Question
Related Questions
Insure that the player can't increase speed when over the speed limit 3 Answers
How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer
Unity car tutorial speed boost 1 Answer
Wheel rotation help cant work out the problem? 0 Answers
Ball Addforce Acceleration Speed 1 Answer