Home > database >  Why the object is never rotating towards the target?
Why the object is never rotating towards the target?

Time:07-20

void Update()
    {
        if (pickUp)
        {
            if(Roll.hasStopped)
            {
                animator.SetTrigger("Walk Forward");
                Vector3 targetDirection = (target.position - transform.position).normalized;
                target.rotation = Quaternion.LookRotation(targetDirection);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, target.rotation, Time.deltaTime);
            }
        }
    }

The transform is the player and he is start walking forward "Walk Forward", but he never rotate towards the target. he keep moving straight walking forward.

The "Walk Forward" is a trigger parameter i'm using in my animator controller on a transition to a state with HumanoidWalk animation.

The question is why the transform is not rotating towards the target and keep walking straight forward instead ?

CodePudding user response:

Maybe you're overriding the rotations with the animator.SetTrigger? Idk too much of animation, but It seems odd to me that animator.SetTrigger is called in every frame and after that there's no flag raised to stop calling it over and over. From what I've seen in the docs, this trigger gets called after a certain event (i.e press a key) but not in every frame. Hope it helps :)

  • Related