Move Character Standard Speed

I’m having a little problem
when I move my character forward or backward
either up or down, it reaches normal speed
but if I move it diagonally his speed increases
and this can not happen in any game right?
Anyone know what it takes to achieve a standard rate velocity for all angles?

void moveJogador_func(){
		CharacterController controller = GetComponent<CharacterController>();
       	
		vt = new Vector3(-Input.GetAxis("Vertical"),0,Input.GetAxis("Horizontal"));		
		vt = transform.TransformDirection(vt * vl);
		vt.y -= gravidade * Time.deltaTime;
		controller.Move(vt * Time.deltaTime);

That's not a comment :P

Ha, you got me =]

1 Answer

1

vt = new Vector3( …
vt = vt.normalized; // Add This Line
vt = transform …

OR

vt = new Vector3( ....
vt.Normalize(); // Change to This Line
vt = transform .....

Note : using GetComponent in the function is not optimal, you should cache the Character Controller in the Start function.

thanks I put this way but when I give a touch too forward it slips is there any way to reduce this slip? vt = new Vector3(-Input.GetAxis("Vertical"),0,Input.GetAxis("Horizontal")).normalized;

What is vl adding? Edit : I see now, the speed modifier.

that way there my character is slipping when I move it in any direction

I don't know. The answer to moving diagonally at the same rate as forward or sideways is to normalize the vector, this then decreases the vector to a magnitude of 1 : http://docs.unity3d.com/Documentation/ScriptReference/Vector3-normalized.html Perhaps try Normalize, as it may be something to do with the way you keep using the same variable for the vector : http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Normalize.html And using GetComponent in the function is a bad idea (not optimal), you should cache the Character Controller in the Start function.

can you tell me how to reduce the slide?