- Home /
Rigidbody2D keeps rotating when freeze position is checked
I'm making a brawl game, the arena is in space, so i followed a slippery movement script, and i made the characters rotate when player press A or D, but the rotating stops as soon as the player stops pressing A or D, i want the characters to keep rotating for 2sec before stopping, so i made a check when player last pressed A or D, and i also made it checked if player was not pressing any keys, and so if player last pressed A or D it will rotate in A or D direction for 2sec and freeze, but its not freezing
here the rotating script
heres the result
the z is checked but it's still rotating
Answer by _DS_1 · Dec 03, 2020 at 05:13 AM
When you use transform.Rotate(), or transform.Move(), the physics settings are ignored in that gameObject. If you want to rotate, or move, with physics use rb.MovePosition() or rb.MoveRotation(), which are similar to the transform methods but take in cosideration the rigidbody settings, or use rb,AddForce() or rb.AddTorque().
You could use AddTorque() for this, or set the angularVelocity to 2f(or -2f) and in Freeze() set the angularVelocity to 0f, or store the rotation value in a global variable and in the Freeze() method set that to Vector.Zero. Or you could use a tween engine like DotTween or LeanTween. But I think the angularVelocity is the best suits you right now. See : https://docs.unity3d.com/ScriptReference/Rigidbody2D.html