# Problem with moving gameObject, especially diagonally!

I am trying to simply character controller without using a rigidbody (since I don't need any physics.) The results are ok, but for some reason my gameObject moves faster when moving diagonally than when just heading in a single direction. Here is my code:

``````void FixedUpdate() {
float xPos = Input.GetAxis("Horizontal") * _player.speed * Time.deltaTime;
float yPos = Input.GetAxis("Vertical") * _player.speed * Time.deltaTime;

Vector3 newPos = new Vector3(xPos, 0, yPos);
newPos = Camera.main.transform.TransformDirection(newPos);
_position = _position + newPos;
_position.y = _player.transform.position.y;

_direction = new Vector3(xPos, 0, yPos);
_direction = Camera.main.transform.TransformDirection(_direction);
_direction.y = 0;
}

void Update() {
if(_direction.sqrMagnitude > 0.01)
_player.transform.rotation = Quaternion.Slerp (_player.transform.rotation, Quaternion.LookRotation (_direction), Time.deltaTime * 10);

_player.transform.position = Vector3.Slerp(_player.transform.position, _position,Time.deltaTime*10);
}

``````

If anyone has any suggestions as to how I can get around this problem or perhaps even improve the above code, I'd really appreciate it!

Change the first three lines to this:

``````    float xPos = Input.GetAxis("Horizontal");
float yPos = Input.GetAxis("Vertical");

Vector3 newPos = new Vector3(xPos, 0, yPos);
if( newPos.magnitude > 1.0f )
{
newPos = newPos.normalized;
}
newPos *= _player.speed;
newPos *= Time.deltaTime;

``````

Since Input goes from -1 -> 1, you'll want to handle the case where x and y are both 1. The length of that is sqrt(2) if you do the trig. You want to just clamp it to 1.

Diagonally u mean when u press 2 keys like w + d in the same time? if yes, u can make a check and if it matches then to decrease the speed by 2.