- Home /
Glitch when erasing rigidbody's velocity to "calculate" new
rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0); rigidbody.AddRelativeForce(Input.GetAxis("Horizontal")*100, 0, Input.GetAxis("Vertical")*100); rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed);
I added the first line to make the object stop as soon as the player releases the button (or rather, as soon as the Axis's value reaches 0) instead of it gliding for a bit. However, the object just moves slowly, and while debuging it stated that rigidbody.velocity was equal to 0.
I've also tried Set(0, rigidbody.velocity.y, 0) and it moves at the expected speed. However, it continues gliding after both input Axis reach 0.
Rigidbody settings
Mass: 1
Drag: 0
Angular Drag: 0.05
Use Gravity: Yes
Is Kinematic: No
Interpolate: None
Constraints
Freeze Position
X: No
Y: No
Z: No
Freeze Rotation
X: Yes
Y: Yes
Z: Yes
If you print velocity as a Vector3 in the debug window, it rounds to the nearest 10th, so a speed of 0.04 appears as 0. Can print individually (or in Inspector vars) to see unrounded values.
By glide, you mean it changes x/z positions? Double-checked using the Inspector (not just an illusion from perspective, as it falls?)
I checked. It still says rigidbody.velocity equals 0 (eventhough it moves) when I use "=Vector3(0, rigidbody.velocity.y, 0)" and it glides/changes x/z values after the input Axis's values reach 0 when I use ".Set(0, rigidbody.velocity.y, 0)"