简体   繁体   中英

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's the rotating script

Here's the result

the z is checked but it's still rotating

The freeze option of the rigidbody handles/freezes the rotation regarding the physics, this is when a force is applied and you have forces, inertias etc. If you move the transform direcctly in the code this is not the case so the rigidbody component does not freeze/handle that approach. You should define the gameObject movement either moving the element directly moving its transform with code, or adding forces and letting the rigidbody handle the movement, but not both.

The FreezeRotation of the rigidbody has this definition: If freezeRotation is enabled, the rotation is not modified by the physics simulation. But it seems like you are rotating the object with the script ( even if I don't see that part in your photo). If you want to rotate the object only with script and not with gravity or physics you should always set has true freezeRotation and control the rotation only with the script with a transform.Rotation = Quaternion.Euler() and stop it with the same method. Physics will never change rotation and you will decide how to stop it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM