C# 2D Ai scripting. 4 Directional.
I will start off by saying I'm a beginner in game dev. I'm having trouble finding any sort of help whatsoever on scripting an Ai that moves 4 directional, Moves up faces up, etc. I've googled and searched Reddit multiple(over 10) times for help.
My Ai needs to chase the player over a map, No need to set up "within distance" I do use a blend tree for the animations of the Ai.
The closest I ever got to finding scripting for the Ai was in gamesplusjames tutorial Unity RPG Tutorial. but he didn't get into how to trigger blend tree animations since his Ai only faced one direction. Here is my character scripting below to give you an idea of what I am talking about, since I seem to be easily misunderstood by lots.
I'd like a tutorial on how to do it or at least some kind of source with the code that explains how it works. I want to learn! I pray somebody here can help me.
void Start () {
rbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (movement_vector != Vector2.zero)
{
anim.SetBool("iswalking", true);
anim.SetFloat("Input_X", movement_vector.x);
anim.SetFloat("Input_Y", movement_vector.y);
}
else
{
anim.SetBool("iswalking", false);
}
rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime * 2f);
}
}