How to use Vector2 movetowards?

I have been following a blackthornprod tutorial to help create a boss battle and I’ve come across a problem with “Vector2.MoveTowards”.
So I’ve created a boss character who moves and jumps (Planning to add some more attack ect.)
and the Vector2.Movetowards isn’t working at all. The animations are working fine. I’ve tried increasing and decreasing the speed, checked whether the “Player” tag was spelt correctly and the boss does not move whatsoever.
I will appreciate any help!


private float timer;
public float minTime;
public float maxTime;
private Transform playerPos;
public float speed;
float elapsedTime;

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    timer = Random.Range(minTime, maxTime);

override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    if (timer <= 0)
        timer -= Time.deltaTime;
    Vector2 target = new Vector2(playerPos.position.x, animator.transform.position.y);
    animator.transform.position = Vector2.MoveTowards(animator.transform.position, target, speed * elapsedTime);
    elapsedTime += Time.deltaTime;

override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)


I have same issue, in a 3D game! Would love to know the solution,Would love to know an answer to this, i’m making a 3D game but have the same issue!

For those who come accross this post:
I had a similar problem recently. It was caused by the “Apply Root Motion” flag. Unchecking it in the Animator component solved my problem.