how do i switch between different Ai directional walk animations using a blend tree?
I am practicing Ai behaviors in a top-down 2d environment. I have a blend tree with 4 directional walk animations set up for my Ai; however, I can't get the Ai to switch between the animations depending on the direction they are walking in. my animator only has a movement blend tree on entry and nothing else. for the parameters I was thinking about using 3 floats; horizontal, vertical, and speed. To add, I have 2 scripts that I want to attach to the enemies, the first one is the "patrol" script that I plan to attach to all of the Ai enemies in the scene, this script makes the Ai go from a waypoint to another and then keep moving between them infinitely for now. this is the script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Patrol : MonoBehaviour
 {
     public Transform[] waypoints;
     public float moveSpeed;
     int waypointIndex = 0;
     private void Start()
     {
         transform.position = waypoints[waypointIndex].transform.position;
     }
     private void FixedUpdate()
     {
         move();
     }
     void move()
     {
         transform.position = Vector3.MoveTowards(transform.position, waypoints[waypointIndex].transform.position, moveSpeed * Time.deltaTime);
         if(transform.position == waypoints[waypointIndex].transform.position)
         {
             waypointIndex += 1;
         }
         if(waypointIndex == waypoints.Length)
         {
             waypointIndex = 0;
         }
     }
 }
the second script is enemy-specific. for now, I was thinking about making it switch between the directional walk animations but my problem is that I don't know what I should pass to the horizontal and vertical parameters of the blend tree to make the switch trigger. Here is the script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class GuardAiMovement : MonoBehaviour
 {
     public Rigidbody2D rb;
     public Animator animator;
     Vector2 movement;
     void Update()
     {
        // i know that my Rigidbody has no velocity in this environment but i didnt know what to use other than that
         movement.x = rb.velocity.x;
         movement.y = rb.velocity.y;
         animator.SetFloat("Horizontal", movement.x);
         animator.SetFloat("Vertical", movement.y);
         animator.SetFloat("Speed", movement.sqrMagnitude);
     }
 }
the Ai has a Rigidbody 2D, collider, animator component, and both of the scripts are attached to it. any kind of help is appreciated.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                