- Home /
Gravity is not working if i use rigidbody.velocity
Hi, I need object which move on axis x, but when I use rigidbody.velocity so gravity is broken on object. I used advice from answers already but i can't still find solution.
Thanks for every advice!
private Rigidbody rb;
public float spd = 200;
void Start () {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate () {
rb.velocity = new Vector3(-spd, 0, 0) * Time.deltaTime;
}
Answer by FortisVenaliter · Apr 13, 2017 at 10:14 PM
Correct. The Rigidbody is a physics object. So, it uses forces to manipulate the velocity. When you write to the velocity like that, you override any forces applied to it.
What you want to do instead is use AddForce until it gets to the appropriate speed.
Also, the velocity is already using the time natively, so multiplying the velocity by the time is actually making it run on squared time, which could have wonky effects.
Your answer
Follow this Question
Related Questions
Object shattering under a certain weight/force 3 Answers
Multiple Cars not working 1 Answer
How to add gravity without a rigidbody 2 Answers
How to enable gravity on gameobject when interact by player 3 Answers