66 lines
1.8 KiB
C#
Raw Permalink Normal View History

2026-01-07 12:00:57 +05:30
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)
2026-01-07 12:00:57 +05:30
{
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);
2026-01-07 12:00:57 +05:30
}
protected override void Update()
2026-01-07 12:00:57 +05:30
{
base.Update();
// keep roaming for a specific duration
2026-01-07 12:00:57 +05:30
// 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-
2026-01-07 12:00:57 +05:30
// -(next state could be ChargeState)
// Set Target location
if (!hasCompletedRoaming)
{
roamTimerSystem.UpdateTimer(Time.deltaTime);
aiCarDriver.UpdateMovement();
}
else
{
base.Exit();
nextState = new AcquireTargetState(aiCarDriver, gameplayManager);
}
2026-01-07 12:00:57 +05:30
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}