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