- Home /
How would I animate a 2D enemy with AI made with A*?
So recently I decided to get started on a pixel art top down RPG. It's the first game I've actually had the proper motivation to create but I recently hit a roadblock. I had followed a tutorial on how to create 2D enemy AI by Brackeys and ran into no problems in setting up A*. The problem arose when I was trying to animate my enemy. I had created the animation files and made an animation tree, when I realised I had no clue how to link my enemy with its animations. I tried to solve the issue myself. I thought about but could see no other way for this to work other than the following script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoblinAnim : MonoBehaviour
{
Vector2 movement;
public Animator anim;
// Update is called once per frame
void Update()
{
anim.SetFloat("Horizontal", movement.x);
anim.SetFloat("Vertical", movement.y);
anim.SetFloat("Speed", movement.sqrMagnitude);
}
}
However, this did not work. Though I did not encounter any errors in console, my goblin was still as rigid as ever. My surface level understanding of Unity could not find any solution to this problem other than posting on here. If any of you have any clue at all about this, I'd appreciate your input.
Do you have your animator controller setup to have transitions based upon the value of horizontal, vertical etc? Do you have an avatar created and assigned?
you need to see whats happeing in the animator window, with that information we cant help you
Your answer
Follow this Question
Related Questions
Kill character on impact 1 Answer
Why do the AI get caught on trees? 0 Answers
Nav Mesh Agent 0 Answers