- Home /
Formula for acceleration to reach max velocity
Hi!
I tried to get a formula for calculating max velocity of a rigidbody, but after couple of days of trial and error, where I tried to apply some physics formulas to find my values I got nothing because I was unable to figure out how unity calculates all of this.
I got some results from this formula found on the forums(without gravity and friction):
maxVelocity = ((force.magnitude / drag ) - fixedDeltaTime * force.magnitude )/ mass;
and force is just:
Vector3.forward * mass * acceleration;
Right now I need to set the acceleration to achieve max speed, but can't quite get the formula right for this. Is it even possible? I have tried transforming this formula, but I failed :/ (the shame!)
This is for a rigidbody without gravity and any friction.
some code:
public Rigidbody r;
public float acceleration = 1f;
public float currentForwardSpeed ;
private Transform _t;
private float force;
void Start()
{
_t = GetComponent<Transform>();
acceleration = ???????
force = _t.forward * r.mass * acceleration;
}
void FixedUpdate)
{
currentForwardSpeed = _transform.InverseTransformDirection(_rigidbody.velocity).z;
if(Input.GetKey(KeyCode.W))
{
float maxVelocity = ((force.magnitude / r.drag ) - fixedDeltaTime * force.magnitude )/ r.mass;
}
}
If the velocity is supposed to instantaneously change, you can just set the velocity directly: r.velocity = direction * maxVelocity
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613192835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
add force to object that has 2 different rigid bodies 0 Answers
Confusion with AddForce with ForceMode.Acceleration 1 Answer
How to calculate force to apply to move object to a certain distance. 1 Answer
Adding a position offset to a force towards an object 1 Answer
How to drive Rigidbody.AddForce acceleration correctly from Update 1 Answer