- Home /
Stop velocity on rotation change
I currently have a problem where I have an object that can rotate, and is always moving forward. The problem is that when I change direction, the object takes some time to slow down, and move the other way. I want the object to change velocities instantly.
I have tried setting the rigidbody velocity and angular velocity to zero, but it doesen't work. I have also tried making the object kinematic, but that also doesn't work. Are there any thoughts on how to solve this?
Answer by We_we_we · Jul 06, 2016 at 07:27 AM
I found a solution that was quite simple. At the beginning of each frame I set a vector 3 equal to the objects position. Then, in my move function, I set the objects position to the vector 3 I made before moving the object forward. This seems to reset the objects velocity every frame, thus, making the movement much more accurate and stable.
Based on your initial description, would something like this have been adequate?
// C#
Rigidbody rb; // For reference
// ...
void FixedUpdate()
{
float currentSpeed = rb.velocity.magnitude;
rb.velocity = transform.forward * currentSpeed;
}
Answer by We_we_we · Jul 04, 2016 at 01:32 PM
After I bit of messing around I came up with a quite simple solution. At the beginning of Update, I set a V3 equal to the objects position. In my move script, I set the objects position equal to the new V3 before moving the object. This seems to remove any velocity before it becomes out of control.
Hopefully this will help anybody with the same problem I had.
Your answer
Follow this Question
Related Questions
Calculate Angular Velocity to Match Remote Position 0 Answers
A way to kill rotation made by rigid body pysics? 1 Answer
Rotating a moving object 0 Answers
Rigidbody Disable Velocity/Movement? 1 Answer
Stopping a rigidbody immediately 2 Answers