# rigid body moves faster diagonally even when normalized?

hello.

i have 3d rigid body player using add force. even when normalized it moves faster diagonally (analog stick). how to fix.

thanks,

p.s. i can see the values coming out of normalize are like .4 and .9 diagonally together. is that normalized? seems that would be higher than 1 to me.

There is not a problem with normalized, you have a logic error in your code. Add in some Debug.Log() statements and see what is happening.

If you want more help, you need to write a small replicator code and post it here explaining what you expected to happen and what is happening. I would suggest you try to make your replicator use a keyboard for input as people without controllers probably won’t bother looking otherwise. You should be able to post something trivial that moves a cube around on a plane to illustrate the diagonal issue.

normalized means the magnitude (length) of the vector is equal to 1. In a 2D sense this is the length of the hypotenuse of a right angled triangle. For example if you had x = 0.40 and z = 0.92 your magnitude would be 1

Sqrt(0.40^2 + 0.92^2) = 1

whoa. sounds like its working properly then.

well then what i dont get is why every tutorial says add normalize, or normalized, (whichever, cant remember), to your input vectors and then it wont run faster diagonally. and they work. but for me suddenly, they stopped working. are they not supposed to work? sounds like no after reading this, but im sure ive seen them work.

also, they used to work for me when i used character controller instead of rigidbody. strange.

ill check my code again.

Firstly, I would reiterate my advice to make a simple replicator that just moves a cube around on a flat surface - you will probably figure out your issue in making it, and if you don’t, posting the code will make it easier for the rest of us to assess the problem.

Normalize is a very simple method to make sure a vector has a magnitude of 1, whatever the initial values were*. However, you need to consider two important things:

1. If you are hoping to use non-binary inputs, e.g. analogue control sticks, then realise that normalizing will give you an output of magnitude 1, so pushing the stick half way will not let the player move at half speed.

2. *Normalized vectors are always magnitude 1, (unless the initial values produce a magnitude < 1e-5, in which case Vector3.zero is returned). So you may get an output direction even when you are expecting (near) zero due to input decay or floating point precision.

You may want to look at Vector3.ClampMagnitude instead, which you could use to allow a vector of magnitude 0 to 1.

Edit:
I just found this, which may interest you Morten Andersen