There are some issues in this video. Firstly, you are not starting the timer in Visual Studio Code EnemyChaseState.cs. Secondly, the position is still updating even though the timer may be stopped. Lastly, as the player moves, there has to be a reference to the old position that the enemy is chasing while the timer is running and the new position that the player as moved to once the timer stops. So here is the code that is working. So consider redoing the video with the following code:
using Godot;
using System;
using System.Linq;
public partial class EnemyChaseState : EnemyState
{
[Export] private Timer timerNode;
private CharacterBody3D target;
private Vector3 oldPosition;
private bool isTimerRunning = false;
protected override void EnterState()
{
characterNode.AnimPlayerNode.Play(GameConstants.ANIM_MOVE);
target = characterNode.ChaseAreaNode.GetOverlappingBodies().First() as CharacterBody3D;
oldPosition = target.GlobalPosition; // Store the old position
timerNode.Start();
timerNode.Timeout += HandleTimeout;
isTimerRunning = true;
}
protected override void ExitState()
{
timerNode.Stop();
timerNode.Timeout -= HandleTimeout;
isTimerRunning = false;
}
public override void _PhysicsProcess(double delta)
{
if (!isTimerRunning){
destination = oldPosition; // Chase the old position
characterNode.AgentNode.TargetPosition = destination;
Move();
}
}
private void HandleTimeout()
{
//GD.Print("Timeout!");
oldPosition = target.GlobalPosition; // Update the old position
destination = oldPosition;
characterNode.AgentNode.TargetPosition = destination;
isTimerRunning = false;
}
}