Ashby Issac c466e28d6c AI FSM changes.
- Protoyped on the AI movement, found solutions for turns and
   moving after impacting the player.
- Created a full base for AI state machine.
- Worked on binding the core AI logic with the finite state machine.
2026-01-07 19:38:03 +05:30

66 lines
1.8 KiB
C#

using UnityEngine;
public class RoamState : BaseState
{
private bool hasCompletedRoaming = false;
private float roamDuration = 2f;
private Vector3 currentRoamingPoint = Vector3.zero;
private TimerSystem roamTimerSystem = null;
public RoamState(AICarDriver aiCarDriver, GameplayManager gameplayManager) : base(aiCarDriver, gameplayManager)
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
// get the target point
currentRoamingPoint = gameplayManager.GetRoamingPoint();
aiCarDriver.SetTargetPosition(currentRoamingPoint);
roamTimerSystem = new TimerSystem();
hasCompletedRoaming = false;
roamTimerSystem.Init(roamDuration, onComplete: () => hasCompletedRoaming = true);
}
protected override void Update()
{
base.Update();
// keep roaming for a specific duration
// use a set of target points which would be placed on the arena,
// get one of the target point and then start roaming towards that point.
// if an enemy/player is found within a specific radius and in front of-
// -the AI then go to the next state after acquiring the target-
// -(next state could be ChargeState)
// Set Target location
if (!hasCompletedRoaming)
{
roamTimerSystem.UpdateTimer(Time.deltaTime);
aiCarDriver.UpdateMovement();
}
else
{
base.Exit();
nextState = new AcquireTargetState(aiCarDriver, gameplayManager);
}
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}