# Why does enabling freeze rotation on Z causes odd behavior?

Hi everyone
I’m working on a small platformer project, I just started so I’m programming the first enemies (I already coded the player controls) and I noticed something when I enable freeze rotation on the Z-axis, the enemies suddenly stop moving. I made them chase the player, so depending on the player’s X position is the direction that I am moving them, however, they randomly stop moving and when I move the player to the opposite side the enemies will resume their chase for a while until they get stuck again.
And as I told you before, I already programmed the controls for the player and I left the freeze rotation checked and I had no issue with that, only with the enemies.
This is the code I use for moving the enemy

``````private void ChasePlayer()
{
currentState = HellhoundStates.Chasing;
anim.SetFloat("Speed", Mathf.Abs(rb.velocity.x));
bool goingRight=true;
if (transform.position.x - playerTransform.transform.position.x > reachTargetOffset)
{
goingRight = false;
}
else if (transform.position.x - playerTransform.transform.position.x < -reachTargetOffset)
{
goingRight = true;
}
if (goingRight)
{
rb.velocity = new Vector2(speed * Time.deltaTime, rb.velocity.y);
transform.eulerAngles = new Vector3(0, -180, 0);
}
else
{
rb.velocity = new Vector2(-speed * Time.deltaTime, rb.velocity.y);
transform.eulerAngles = new Vector3(0, 0, 0);
}
}
``````

Note: rb is the Rigidbody2D*

Unchecking the freeze rotation field fix this issue, however, I would not like to leave it that way since I’m going to need the enemies sometimes to fall from above or something like that and I don’t want them to be rolling around
Thanks!

A Rigidbody2D is in charge of the transform so you should not be changing it in the first place. Also, there’s no point in asking the Rigidbody2D to stop rotation when you’re explicitly overriding the rotation of the Transform (and thus the Rigidbody2D rotation). On top of this, I presume you’re doing all this per-frame? Know that physics (by default) doesn’t run per-frame and runs during the fixed-update.

It’s odd to “flip” using rotation, it’s typically done using transform scale. Even this should only be done when something changes, not constantly being set. If your character isn’t complex then you can flip the SpriteRenderer in XY axis which is far more performant and doesn’t impact anything else.

Thank you!

Changing my method to FixedUpdate instead of Update helped a lot. And Fliping my sprite with the FlipX field fixed it, it no longer gets stuck!