image rotating incorrectly

I’m trying to have A UI image rotate to be over a specific weapon I can using this codeselectedImage.rectTransform.rotation = new Quaternion(0, 0, 90 * (weaponState - 1), 0); , with weaponState being an int between 1 and 4 however, for some reason whenever the weaponState anything other than 1 the rotation becomes -180. the model of the weapon changing shows me weaponState is changing correctly and a debug right under this line tells me it’s calculating correctly so why does the rotation not go to where it’s supposed to? it works fine when weaponState changes to 1 but anything else glitches.

The values you are entering are incorrect as that’s not how quaternions work. By the looks of it, you are confusing Euler angles with Quaternion values. Try using Quaternion.Euler instead. So;selectedImage.rectTransform.rotation = Quaternion.Euler(0, 0, 90 * (weaponState - 1));

1 Like

Yes that seems to have been the problem, thanks.