Rotation clamp

How to clamp rotation of object like in the game wobble 3d?

One thing to keep in mind about rotation is that Euler values should only ever be written to, never read from. This means that you can’t just clamp the Euler values of the rotation and call it a day.

What you should do instead is track the amount in both axes that the object is to be rotated outside of the rotation itself, and clamp those values. So, you’d have two floats xRotation and zRotation, make the user input change those values frame to frame, clamp them, and assign them to the rotation via Quaternion.Euler.

Can you help me in the code ?

If you post it, we can look at what you need and what the problem is. Asking “Can you look at my code” is a bit of a weird way of asking for help. Post the code in question and the problem you are having, be as clear as possible and we can probably figure out what needs to be changed.

private Touch touch;

private Vector2 touchposition;

private Quaternion rotationx, rotationz;

private float tiltspeedmodifier = 0.1f;

void Update(){

if(Input.touchCount>0)
{

touch = Input.GetTouch(0);

switch(touch.phase){

case TouchPhase.Moved:

rotationx=Quaternion.Euler(
-touch.deltaPosition.x * tiltspeedmodifier,0f,0f);

transform.rotation= rotationx * transform.rotation;

rotationz= Quaternion.Euler(
0f,0f, -touch.deltaPosition.y * tiltspeedmodifier);

transform.rotation= transform.rotation * rotationz;

break;

}

}
}
}

I need rotation clamp in this.

When you post code, use code tags.

Make rotationx and rotationz floats instead of Quaternions, and add the appropriate deltaPosition value to them each frame. It’ll look a little bit like:

float rotationx = 0f;
void Update() {
...
rotationz += Input.deltaPosition.x;
transform.rotation = Quaternion.Euler(rotationx, 0f, rotationz);

Kind of confused here, can you elaborate the code?