Search Unity

Changing player rotation to camera direction make legs go crazy

Discussion in 'Animation' started by Snappx, Jan 31, 2020.

  1. Snappx

    Snappx

    Joined:
    Sep 29, 2019
    Posts:
    1
    This is how I rotate player position
    Code (CSharp):
    1.    if (Input.GetMouseButton(0) || Input.GetButton("Vertical"))
    2.             {
    3.                 target.transform.rotation = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0);
    4.             }
    5.             else
    6.             {
    7.                 target.transform.Rotate(0, Input.GetAxis("Horizontal") * 1 * Time.deltaTime, 0);
    8.             }
    Everything works fine but when i go forward my legs go right - left , right-left , they dont go straight , if i remove the code above player runs fine. Why ?

    If more details needed please ask.

    Edit:I found that is because " if (Input.GetMouseButton(0) || Input.GetButton("Vertical"))" is always true when W is pressed so my player(target) is always rotating.
     
    Last edited: Jan 31, 2020