Im making a basic flying game. There is a relative force pushing the plane forward and i want to steer the plane with my mouse.
I have found a code and it works but feels very awkward. I wanted to invert the controlls once the plane is at a z rotation of 90 degrees so that it hopefully feels more intuative.
I am very new to coding, 2 days in, and I dont know how to fix my code so it runs
the part in question is as follows (red is the part with the error):
//senstivity multiplier
public float Sens = 2.00f;
// Locate Z rotation. If Z rotation is between 90 and -90 then use non-inverted control as follows
if (transform.localEulerAngles.z (< 90 && > -90)); {
//non-inverted control
transform.Rotate(Input.GetAxis(“Mouse Y”) * Sens , 00.0f, -Input.GetAxis(“Mouse X”) * Sens ); }
//otherwise, invert the control
transform.Rotate(Input.GetAxis(“Mouse X”) * Sens , 00.0f, Input.GetAxis(“Mouse Y”) * Sens );
Not sure why its wrong or how to fix it, any help appreciated!
You always have to check variables condition for condition, even if you check the same variable twice.
//Locate Z rotation. If Z rotation is between 90 and -90 then use non-inverted control as follows
if (transform.localEulerAngles.z < 90 && transform.localEulerAngles.z > -90)
{
//code for non-inverted control
}
//Otherwise use inverted controls
else
{
//code for inverted control
}
Ok so the issue is it works when turning left (z rotation is positive) but as soon as the player has a -z rotation it instantly inverts despite not meeting the invert requirement (z < -90)
That’s because the angles never actually are below 0, they are always between 0 and 360, the unity editor just shows it as if they were below 0.
So instead of