- Home /
Unity 5 character movement problem with strafing left and right,Cannot get rid of left and right strafing. Help Please!
Hello guys, since yesterday I have been having a problem with my character movement. The character moves well. I mean he goes forward and backwards, left and right however I would like him go left and right only when he is walking backwards of forwards rather than just strafe to the left or to the right because I don't have animations for just walking left or right and I have some for diagonal walking and running which work fine so yeah... Can anybody help? Remember the objective is to move left and right by pressing A and D keys only when W or S is pressed, otherwise just pressing A or D should result in no movement
Here is my code for Handling the movement of the character:
private void HandleMovement(){
float translation = walkSpeed * Time.deltaTime;
transform.Translate (new Vector3 (Input.GetAxis ("Horizontal") * translation, 0, Input.GetAxis ("Vertical") * translation));
}
,Hello guys, since yesterday I have been having a problem with my character movement. The character moves well I mean he goes forward and backwards, left and right however I would like it go left and right only when I am walking backwards of forwards rather than just strafe to the left or to the right because I don't have animations for just walking left or right and I have some for diagonal walking and running which work fine so yeah... Can anybody help? Remember the objective is to move left and right by pressing A and D keys only when W or S is pressed, otherwise just pressing A or D should result in no movement
Here is my code for Handling the movement of the character:
private void HandleMovement(){
float translation = walkSpeed * Time.deltaTime;
transform.Translate (new Vector3 (Input.GetAxis ("Horizontal") * translation, 0, Input.GetAxis ("Vertical") * translation));
}
Just include a quick if() check before translating - like so:
private void Handle$$anonymous$$ovement()
{
float translation = walkSpeed * Time.deltaTime;
if(Input.GetAxis("Vertical") != 0)
{
transform.Translate (new Vector3 (Input.GetAxis ("Horizontal") * translation, 0, Input.GetAxis ("Vertical") * translation));
}
}