Float to Vector 3?

Im doing some very simple tests until i tried to do a ball like character. Obviously i have some problems with crazy directions and things like that. Then i tried to look for some example and found M2Hs Unity Game Examples with a marble game. Great! I thought.
However, looking at marble movement script, i found this piece of code:

Vector3 movement = (Input.GetAxis(“Horizontal”) * -Vector3.left * movementSpeed) + (Input.GetAxis(“Vertical”) * Vector3.forward *movementSpeed);

Ok…
“movement” is a Vector3 and (Input.GetAxis(“Horizontal”) * -Vector3.left * movementSpeed) + (Input.GetAxis(“Vertical”) * Vector3.forward *movementSpeed) looks like it`s returning a float. O.O

It work very well but… HOW???
I tried to copy and paste this code in my script and didn`t work ( ‘;’ expected. Insert a semicolon at the end.).

Solved by myself -.-
Input.GetAxis() returns a Vector3
Vector3.left and Vector3.forward are both Vector3
movementSpeed is a float and it can be multiplied by a Vector3. The result is a Vector3.

So (Input.GetAxis(“Horizontal”) * -Vector3.left * movementSpeed) + (Input.GetAxis(“Vertical”) * Vector3.forward *movementSpeed) returns a Vector3.

False.

If it were, you couldn’t multiply it by a Vector3, because the Vector3 * operator only works with floats. Now, multiplying by it is bad code anyway, but that’s beside the point.

1 Like