Search Unity

Question Blend Tree Head of Player Character keeps tilting horizontaly.

Discussion in 'Animation' started by Alexdbz, Mar 11, 2023.

  1. Alexdbz

    Alexdbz

    Joined:
    Dec 5, 2022
    Posts:
    4
    I can't seem to find a way to resolve this issue, when I am moving my character just the head moves it looks weird
    I made a video to make it clear what I am trying to say.

    also here are my animation and movement scripts hope it helps In order not to make this too long I will just copy my movement script, rotation, and Animator methods hope It helps. I am using Unity event movement system.

    public void Move() // Move is then updated in void FixedUpdate() // Just didnt want to copy here // Players RigidBody is in Void Awake()
    {
    float speedMultiplier = isRunning ? 2.0f : 1.0f; // Set speed based on running state
    if (Keyboard.current.leftShiftKey.isPressed)
    {
    speedMultiplier *= 0.5f;

    }
    float speed = movementSpeed * speedMultiplier;


    Vector3 movementDelta = new Vector3(inputVector.x, 0, inputVector.y) * movementSpeed * speed * Time.deltaTime;
    PlayerRb.MovePosition(transform.position + movementDelta);


    for Player rotation using RigidBody its this. //This is also updated in void FixedUpdate()

    private void Rotate()
    {
    if (inputVector.magnitude > 0)
    {

    Vector3 direction = new Vector3(inputVector.x, 0, inputVector.y);
    Quaternion targetRotation = Quaternion.LookRotation(direction);


    transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * 1000);
    }
    }
    }
    and this is for Animator
    public void Update()
    {

    UpdateAnimatorVelocity();

    }

    private void UpdateAnimatorVelocity()
    {
    float velocity = animator.GetFloat("Velocity");


    if (playerControlls.inputVector.magnitude > 0)
    {
    velocity = 0.5f;
    if (Keyboard.current.leftShiftKey.isPressed)
    {
    velocity = 1f;
    }
    }
    else
    {
    velocity = 0f;
    }
    animator.SetFloat("Velocity", velocity);
    }
    }