Obstacle Course Lesson Time.delta Time normalize movement

Is there a way we can stop the diagonal movement from being faster than the horizontal or vertical? I know unity has a built in function to normalize diagonal movement, (.normalized), but I’ve only used that with a Vector2 before. Can that be applied here?

Hi,

Yes, that’s possible. The Vector3 struct has got a normalize property, just as you said. See here.

Do you want to challenge yourself and try to solve this problem yourself? If not, here is how it should hopefully work:

Vector3 movement = new Vector3(xValue, 0f, yValue);
Vector3 normalisedMovement = movement.normalize;
transform.Translate(normalisedMovement);

Feel free to rename the variables.

Did this help?


See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms