PatrolState - jimdroberts/FishMMO GitHub Wiki
AI state for patrolling behavior. Handles waypoint selection and transitions for NPCs.
-
public override void Enter(AIController controller)
Called when entering the Patrol state. Picks the nearest waypoint to start patrolling. Parameters: - AIController controller: The AI controller.*
-
public override void Exit(AIController controller)
Called when exiting the Patrol state. Can be used for cleanup. Parameters: - AIController controller: The AI controller.*
-
public override void UpdateState(AIController controller, float deltaTime)
Called every frame to update the Patrol state. Handles randomization and waypoint transitions. Parameters: - AIController controller: The AI controller. - float deltaTime: Frame time.*
- Create a new PatrolState asset via the Unity Editor (Assets > Create > FishMMO > Character > NPC > AI > Patrol State).
- Assign the state to an AIController for NPCs that require patrolling behavior.
- Implement waypoint logic in the AIController as needed.
// Example 1: Assigning the Patrol state to an AI controller
AIController ai = ...;
PatrolState patrolState = ...;
ai.ChangeState(patrolState);
// Example 2: Customizing waypoint logic in AIController
public class MyAIController : AIController {
public override void PickNearestWaypoint() {
// Custom logic for picking waypoints
}
}
- Implement robust waypoint logic in the AIController for smooth patrolling.
- Use Enter and Exit for setup and cleanup when transitioning between states.
- Transition to appropriate states when randomization or waypoint conditions are met.
- Document custom AI state logic for maintainability and clarity.