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);
}
0

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.