2

I am able to clamp the z rotation of my game object using the code below, but it always changes the y rotation on my first touch. I only want to rotate the z-axis.

private float zRotation;

public void RotateMove()
{
    zRotation -= Input.GetTouch(0).deltaPosition.y * rotateSpeed * invert * Time.deltaTime;
    
    // this limits the rotatioon
    zRotation = Mathf.Clamp(zRotation, -80, 80);
    //this rotates the game obj
    lamp2Rotate.transform.eulerAngles = new Vector3(0.0f, 0.0f, zRotation);
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
Seve
  • 39
  • 6

1 Answers1

0

sounds like 0 is not what you want for Y

You could instead keep the other two rotations:

var eulerAngles = lamp2Rotate.transform.eulerAngles;
eulerAngles.z = zRotation;
lamp2Rotate.transform.eulerAngles = eulerAngles;
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Is there a way to prevent this from rotating on z axis on first touch before touchphase.moved. It moves imediately I touch the screen, but I want it to do that after touchphase.moved – Seve Aug 02 '20 at 09:10