Using .move(), the enemy moves faster at a diagonal


direction = _player.position - transform.position;
direction.y = 0;
direction = Vector3.Normalize(direction);
velocity = direction * _moveSpeed * Time.deltaTime;

Why does the enemy have variable speed at different angles when using:


While the enemy has constant speed no matter the direction using:

_controller.transform.position += velocity;

I’d prefer to use the .Move function but what is going on in it? Why isn’t the speed constant?

Normalize scales all the values down so the max value is one. So if x=1 and z=1 you would essentially be moving at a speed of 1.4(square root of 2) instead of 1 in the x or z direction.

Try using:


Instead of:

direction = Vector3.Normalize(direction);

Character Controller

Since normalizing the movement vector results in a movement vector that is always 1 in length, you lose the granularity/interpolation functionality of an analog stick, so I would like to refer to the following Unity forum post:

…where I found the solution to my similar problem, when using the analog stick on my controller.

Quote from cranky:

Normalizing [the movement vector] isn’t always the best
solution. If you’re using a keyboard,
it’s fine. But with an analog stick,
it will always force the length of the
vector to be 1, so you won’t be able
to move slowly. Instead, get the
length of the vector and see if it’s
greater than 1. If so, divide the
movement vector by the length.

…and also (quoting myself)…

Make sure the “Sensitivity” of your
analog stick axes is set to no more
than 1! Mine were set to 2 for some
reason (damn copy/pasting from old
projects), so even when using cranky’s
fix, I had inputs of (1f, 1f) when
within ~30 degrees of either diagonal,
while holding the stick to its
extremity. This made me think there
might be some input-multiplier…and
voila, sensitivity was the culprit.