Search code examples
c#unity-game-enginerotationquaternionseuler-angles

Theta, Phi to Quaternion rotation Unity3D C#


I'm trying to rotate an object in the direction of a given angle that I have Theta & Phi values for. How does this apply when using something like

Vector3 rayRotate = new Vector3 (theta, phi, 0);
beamContainer.transform.rotation = Quaternion.Euler(rayRotate);

Should theta & phi be used directly on the X/Y or do I need to be running a Sin/Cos formula on them?

I have been trying all sort of combinations and varions but I can not get beamContainer pointing in the direction and have this aligned with the object that should be pointing that direction,


Solution

  • I was able to resolve my issue and rotate the beamContainer in the required direction via:

    beamContainer.transform.rotation = Quaternion.Euler(-90 + phi, -theta, 0f);