Break a local rotation value into vector2 components
Hello!
I have a pretty boss formula going for flight in the camera direction, but it's not perfect. At the moment, I'm just taking the localRotation of the camera.
The camera uses horizontal 0, neg numbers up and pos numbers down. in this case, I have done the following:
1-angle, forced it to run as an absolute, then applied it as a factor to horizontal speed,
took vertical movement and reduced it by the angle in speed.
At the moment, if I have a +0.3 down and a -0.3 up, my movement would be forward by 0.7, and either 0.3 down relating to positive values and 0.3 up relating to negative values.
what bothers me is the units this system is using for angular measure.
I tried running pitchlimits in order to decipher this. What kind of number makes vertical 90 degrees equivalent to 0.7071068? This isn't even radians. I was hoping it was equivalent to Gons (100 Gons to 90 degrees), but that's also not the case.
My end game is translating this angle into a tangent horizontal and vertical proportion based on a hypotenuse distance of 1 in order to accurately apply a modifier to flight movement.
What I have below looks nice, but it's not accurate:
(also, I know that I have many extra parenthesis, but I don't trust it's algebraic competency. Believe me. It can and does get worse)
float inclination = Camera.main.transform.localRotation.x;
float inclinationabs = Mathf.Abs (inclination);
float inclinationf = (1 - inclinationabs);
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed * inclinationf;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
float flyspeed = 0;
if (Input.GetAxis ("Vertical") == 0) {
flyspeed = (Input.GetAxis ("fly") * movementSpeed);
} else {
flyspeed = (Input.GetAxis ("fly") * movementSpeed) - (Input.GetAxis ("Vertical") * movementSpeed * inclination);
}
Vector3 speed = new Vector3( sideSpeed, flyspeed, forwardSpeed );