- Home /
Question by
Schaden · May 08, 2020 at 02:04 AM ·
anglelocaleulerangles
I tried to align a piston along an axis.
void SetRotation()
{
float currentRotationAngle = myTransform.eulerAngles.z;
Vector3 axis = label2.transform.position - label1.transform.position;
Vector3 piston = direction.transform.position - scaler.transform.position;
float dRotationAngle = Vector3.Angle(axis, piston);
Vector3 tempAngle = myTransform.localEulerAngles;
tempAngle.z -= dRotationAngle;
myTransform.localEulerAngles = tempAngle;
}
I wrote this function to rotate the piston to fit along a vector called "axis"


And this is what happened
The piston oscillates around the z-axis
How can I fix this problem?
Comment
Your answer