PatrolState - jimdroberts/FishMMO GitHub Wiki

Description

AI state for patrolling behavior. Handles waypoint selection and transitions for NPCs.


API Access

Methods

  • 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.*


Basic Usage

Setup

  1. Create a new PatrolState asset via the Unity Editor (Assets > Create > FishMMO > Character > NPC > AI > Patrol State).
  2. Assign the state to an AIController for NPCs that require patrolling behavior.
  3. Implement waypoint logic in the AIController as needed.

Example

// 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
    }
}

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️