transform.localRotation player change in both position and rotation

Why when using the local rotation, my player’s position will change to another coordinate upon rotate

    public void Turn()
    {
        transform.localRotation = Quaternion.Euler(0, 90, 0);
        GoRight = true;
    }

image

1 Answer

1

When you change the rotation of a GameObject, all GameObjects parented to it will also rotate. If the child GameObjects are not centered to the parent, this will cause them to to change position when you rotate the parent. You need to make sure the child GameObjects are centered to the parent by making the localPosition in the inspector be 0,0,0.
Also, make sure your character is centered in the 3d model.