Question by
crouzilles · Jun 19, 2017 at 12:03 PM ·
rigidbody2ddrag
How to stop drag after reaching a specific speed
Hi everyone,
I have the following code which adds force to a rigidbody2d in a random direction and attempts to set the linear drag to 0 when a specific speed is reached. The problem is that the drag seems to be set to 0 straight away, and I do not understand why, and therefore I am unable to solve the problem
void Update () {
if (Input.GetKeyDown ("space")) {
rb.velocity = Vector3.zero;
Vector3 dir = Random.onUnitSphere;
rb.AddForce (dir * 10, ForceMode2D.Impulse);
}
if (rb.velocity.magnitude <= 1) {
rb.drag = 0;
}
}
Regards Crouz
Comment
Your answer