IdleState - jimdroberts/FishMMO GitHub Wiki

Description

AI state for idle behavior. Handles update rate, entering, exiting, and transition logic for NPCs.


API Access

Fields

  • public float MaxUpdateRate

    If MaxUpdateRate is greater than the base update rate, a random value between the two is used.

Methods

  • public override float GetUpdateRate()

    Returns the update rate for the idle state, possibly randomized between base and max. Returns: - float: Update rate in seconds.*

  • public override void Enter(AIController controller)

    Called when entering the idle state. Stops the AI's movement. Parameters: - AIController controller: The AI controller.*

  • public override void Exit(AIController controller)

    Called when exiting the idle state. Clears look target and resumes movement. Parameters: - AIController controller: The AI controller.*

  • public override void UpdateState(AIController controller, float deltaTime)

    Called every frame to update the idle state. Transitions to random movement if look target is lost or too far. Parameters: - AIController controller: The AI controller. - float deltaTime: Frame time.*


Basic Usage

Setup

  1. Create a new IdleState asset via the Unity Editor (Assets > Create > FishMMO > Character > NPC > AI > Idle State).
  2. Assign the state to an AIController for NPCs that require idle behavior.
  3. Adjust MaxUpdateRate as needed for your NPC behavior.

Example

// Example 1: Assigning the Idle state to an AI controller
AIController ai = ...;
IdleState idleState = ...;
ai.ChangeState(idleState);

// Example 2: Customizing update rate
idleState.MaxUpdateRate = 2.0f;

Best Practices

  • Adjust MaxUpdateRate to control how frequently the idle state updates.
  • Use Enter and Exit to manage movement and look targets for smooth transitions.
  • Transition to appropriate states when the look target is lost or too far away.
  • Document custom AI state logic for maintainability and clarity.
⚠️ **GitHub.com Fallback** ⚠️