how to animate my companion ai

i am trying to animate my ai so that when i move around he moves in all up down left and right just liked the player does my code so far is this
using UnityEngine;
using System.Collections;

public class DogCompanion : MonoBehaviour
{
public Transform player;
public float speed;
public float maxDistance;
public float minDistance;
public Vector2 lastMove;
public string startPoint;
public float attackTime;
public bool canMove;

public float moveX;
public float moveY;
private bool attacking;
private float timer = 0.5f;
private Animator anim;
private bool dogMoving;
private Rigidbody2D myRigidbody;
private static bool dogExists;
private float currentMoveSpeed;
private float attackTimeCounter;
void Start()
{
    anim = GetComponent<Animator>();
    myRigidbody = GetComponent<Rigidbody2D>();
    canMove = true;
    lastMove = new Vector2(0, -1f);

    if (!dogExists)
    {
        dogExists = true;
        DontDestroyOnLoad(transform.gameObject);
    }
    else
    {
        Destroy(gameObject);
    }
}

void Update()
{
    if (Time.timeScale == 0f)
    {
        return;
    }
    dogMoving = false;

    if (!canMove)
    {
        if ((Vector2.Distance(transform.position, player.position) < maxDistance)
&& (Vector2.Distance(transform.position, player.position) > minDistance))
        {
            transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
        }
    }

   

    anim.SetFloat("MoveX", moveX);
    anim.SetFloat("MoveY", moveY);
    anim.SetBool("DogMoving", dogMoving);
    anim.SetFloat("LastMoveX", lastMove.x);
    anim.SetFloat("LastMoveY", lastMove.y);
}

}
i cnt seem to figure out how to get the animation to not require an input from the keyboard

You need to create a blend tree in your animator.

You can check out this tutorial (an official Unity tutorial).

In short, you need to create a single animation parameter, for example “Speed”. Using this parameter you need to create a blend tree between 2 animation states (Idle and Running).

When the Update function is being executed, you need to take the magnitude of the movement vector (new Vector2(moveX,moveY).magnitude) and set it as your speed parameter.
This will set the blending between the 2 animations.

You will need to rotate the companion yourself.