Search Unity

Animating player capsule don't end in correct position

Discussion in 'Animation' started by siennakei, Jul 8, 2022.

  1. siennakei

    siennakei

    Joined:
    Jan 13, 2021
    Posts:
    13
    So I have a player that when enters a trigger box, can press space and it will transform the players position with an animation (sits at the window).

    The animation is very simple, just transform and rotate.

    The player has the animator attached with ;apply root motion' ticked.

    This is the code:

    void Start()
    {
    playerSit = playerCapsule.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
    if (PlayerInRange && Input.GetKeyDown(KeyCode.Space))
    {
    ActivateScript();
    playerSit.Play("PlayerSit");

    }



    }

    public void OnTriggerEnter(Collider other)

    {
    PlayerInRange = true;
    }


    My problem is when the animation plays, it doesn't take into consideration the players current position. It plays the animation, but the player ends up in the totally wrong position.

    Any help would be appreciated.