Hi all.
I’ve been having a bit of trouble with this one and I’ve searched around for quite a while without much success.
I need a Quaternion variable changed into local angles, but I can’t use transform.localRotation or transform.localEulerAngles because I’m not setting the transform at this point, this is just one part of something else that is used to calculate the final result.
This is the snippet of code in question:
Vector3 CalculatePosition(float rotX, float rotY, float currentDistance)
{
Vector3 direction = new Vector3(0,0,-currentDistance);
Quaternion rotation = Quaternion.Euler(rotX,rotY,0);
return TargetLookAt.position + rotation * direction;
}
This function is to calculate the position this object (usually a camera, but not always) should be at next.
TargetLookAt is just an empty object used to keep track of something’s position.
Variables rotX and rotY are floats generated from the mouse x and y axis.
If everything always aligned with world up this wouldn’t be a problem, but since the object we’re tracking isn’t so limited, I need the Quaternion rotation to be local.
I tried something like this:
Vector3 CalculatePosition(float rotX, float rotY, float currentDistance)
{
Vector3 direction = new Vector3(0,0,-currentDistance);
Vector3 rot = transform.TransformDirection(rotX, rotY, 0);
Quaternion rotation = Quaternion.Euler(rot.x,rot.y,0);
return TargetLookAt.position + rotation * direction;
}
While this does adjust the rotation correctly, something goes horribly awry in the conversion and when rotated around the target a certain amount, it completely flips out and starts going all over the place.
As always, thanks for any help or insight you might offer. =)