Hello. I am making a flappy bird clone. I have a problem with rotating the bird object to 45 degrees.
The code works fine and it’s rotating the bird up to 45 degrees as long as the transform.eulerAngles.x is positive.
As soon as it goes to negative value it stops working.
Can anyone explain why?
Do conditional statements work differently for negative rotation values?
This is the code :
public class ByrdController : MonoBehaviour
{
public int score = 0;
private Rigidbody rb;
[SerializeField] float jumpForce = 5.0f;
private void Awake()
{
//just to place the bird straight forward
transform.eulerAngles = new Vector3(0f, 90f, 0f);
}
void Start()
{
//used for jump
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (transform.eulerAngles.x <= 45f)
{
//it rotates it downwards as the bird falls up to 45 degrees
transform.Rotate(1f, 0f, 0f);
}
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
}
public void Jump()
{
//makes the bird jump
rb.velocity = Vector3.up * jumpForce;
//points bird upwards as it jumps
//if i set x value to positive value it works fine
//if i set it negative it stops rotating and stays in the set value (-45f in this case)
transform.eulerAngles = new Vector3(-45f, 90f, 0f);
}
}