How to set enemy animations based on previous player input

Hi! I have an enemy that basically follows the player around using a list of its position and Translates to each position until a collide happens. I’ve sorted out also all the bugs and glitches with the code, but I do have a problem with the enemy’s animations, as I do not know how I can easily trigger the animation based on the player’s earlier input, as the enemy just follows the player’s movement. Any ideas how I can make it work in a pretty simple way? I’m quite new to Unity

My enemy is similar to the Celeste’s enemy Badeline, who follows the player around and matches their exact movements. I just need to figure out how to call the animation at the right time

Normally animations are driven by speed of the movement inputs.

If you have a following agent, do the same, but instead you get the “inputs” by observing the movement of the agent.

Easiest way to observe movement each frame:

private Vector3 previousFollowerPosition;

and in Update():

Vector3 currentFollowerPosition = transform.position;  // this is the agent who follows the player

Vector3 oneFrameMovement = currentFollowerPosition - previousFollowerPosition;

previousFollowerPosition = currentFollowerPosition;   // "age" the data

Vector3 followerVelocity = Vector3.zero;  // assume no velocity

// now scale it up by passage of time, if time is passing
float deltaTime = Time.deltaTime;
if (deltaTime >= 0.001f)
{
  followerVelocity = oneFrameMovement / deltaTime;
}

float followerSpeed = followerVelocity.magnitude;

// now base decisions on what animation for the follower based on the velocity or speed

i have multiple controls on the player: jump, double jump, dash, fall, so I fear it might not observe them correctly. I will try this version, thanks for the tip!

Perhaps you want to just queue the animation events into some kind of time-aware queue that knows how far behind (time-wise) the follower is from the player?

Here’s my reference follow-en-trail package… I suppose you could piggyback other data onto the main stream of data reaching into the past… that stream is the list of PositionInTime objects.

Then instead of just using position / rotation for the follower, you would also reconstruct whatever animations you need the follower to do at that point.

9815508–1410297–FollowEnTrail.unitypackage (6.6 KB)