Zero * Number = ?

Hi guys,

I’m not sure if this is a bug or not but it should be clear since I spent a lot trying to find what is wrong.
My code:

float y = Input.GetAxisRaw ("Vertical") * transform.position.x >= 0 ? -1 : 1;
        Debug.Log ("IN: " + Input.GetAxisRaw ("Vertical"));
        Debug.Log ("OUT: " + y);

Console log:
2664183--187951--lol.PNG

You need to use parentheses. The “>=” is lower precedence than “*”, so it’s being interpreted as:

float y = (Input.GetAxisRaw("Vertical")*transofrm.position.x) >= 0 ? -1 : 1;

or “if the input multiplied by the position is greater or equal to zero, then y = -1, else y = 1.”
You probably want this:

float y = Input.GetAxisRaw("Vertical") * (transform.position.x >= 0 ? -1 : 1);
1 Like

Well I totally forgot about that, thank you so much!