Rotation and angles issue

Hello everyone!

I’m currently making a game where an object needs to be given a force in the Z and Y axis, depending on a given power and angle value. In order to do this I use the following mathematical formula:

powerY = (power * Mathf.Sin(angle));
powerZ = (power * Mathf.Cos(angle));

Here, the angle is determined by the angle of another gameobject (called directionMeter) in Radians (a value between 0 and pi). However, when I used transform.rotation.x, I got a value between 0 and 1, and after a full rotation it would give a value between 0 and -1. I tried using EulerAngles as well, but that gave me a value between 0 and 90, then 270 to 360 (skipping everything between 90 and 270). It seems that Unity is giving me very weird values that I can’t use in my formula. How would I go about solving this?

Hi,

Transform.rotation is a Quaternion so the values of that don’t have a obvious relationship with the angles.

Try looking at Quaternion.ToAngleAxis if you’re not having luck with Euler angles: