how to rotate an object between two angles

Hello everyone.

I’ve an empty object (its a point which is an rotation point and another object imported from Maya) which is a child to this object.
How to rotate this object between for example two angles (-120 and 120 ) on axis y?

1 Answer

1

These are pieces of code you will need.

private Quaternion localRotation;

localRotation.y = Mathf.Clamp(value, -angleLimit,angleLimit);

transform.rotation = localRotation;

for Mathf use namespace - > using System;

value can be anything depending on your need like speed*Time.deltatime, or inputAxis. Anglelimit should be of float declared before , or just use raw float value here

Thx a lot.

I know you marked this as 'Answered', but the solutions is not correct. Quaternions are non-intuitive, 4D constructs that don't use euler angles. The x, y, z, and w parameters go from 0.0 to 1.0. You can use Transform.eulerAngles, but you must be careful. There are multiple euler angle representation for any physical representation, and Unity can change the representation. One one to go is to keep your own Vector3, and treat Transform.eulerAngles as write only.