IAIController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for AI controllers managing NPC navigation, state transitions, and movement logic. Defines the contract for controlling AI-driven NPCs in FishMMO.


API Access

Properties

  • NavMeshAgent Agent { get; }

    The NavMeshAgent component used for navigation.

  • BaseAIState CurrentState { get; }

    The current AI state.

  • Vector3 Home { get; set; }

    The home position for this AI (used for leash and wandering).

  • Transform Target { get; set; }

    The current target for the AI (e.g., enemy, destination).

Methods

  • void Initialize(Vector3 home, Vector3[] waypoints = null)

    Initializes the controller with a home position and optional waypoints. Parameters:

    • home (Vector3): The home position for the AI.
    • waypoints (Vector3[], optional): Optional waypoints for patrol.*
  • void ChangeState(BaseAIState newState, List targets = null)

    Changes the AI state, optionally providing targets for attacking states. Parameters:

    • newState (BaseAIState): The new state to transition to.
    • targets (List, optional): Optional list of targets for attacking states.*
  • void TransitionToIdleState()

    Transitions to the idle state.

  • void TransitionToRandomMovementState()

    Transitions to a random movement state from the available movement states.

  • void SetRandomHomeDestination(float radius)

    Sets a random destination within a radius around the home position. Parameters:

    • radius (float): Radius to randomize destination.*
  • void SetRandomDestination(float radius)

    Sets a random destination within a radius around the current position. Parameters:

    • radius (float): Radius to randomize destination.*
  • void TransitionToNextWaypoint()

    Transitions to the next waypoint in the waypoint array.

  • void PickNearestWaypoint()

    Picks the nearest waypoint to the current position and sets it as the destination.

  • void Stop()

    Stops the agent's movement.

  • void Resume()

    Resumes the agent's movement.


Basic Usage

Setup

  1. Implement the IAIController interface in your AI controller class.
  2. Ensure all required properties and methods are provided.
  3. Use the interface to interact with AI controllers in a generic way.

Example

// Example 1: Implementing IAIController in a custom AI controller
public class CustomAIController : MonoBehaviour, IAIController
{
    public NavMeshAgent Agent { get; private set; }
    public BaseAIState CurrentState { get; private set; }
    public Vector3 Home { get; set; }
    public Transform Target { get; set; }
    // ...implement all interface methods...
}

Best Practices

  • Use the interface to decouple AI logic from specific controller implementations.
  • Implement all methods to ensure consistent AI behavior across different NPC types.
  • Leverage the interface for testing, mocking, or extending AI functionality.
⚠️ **GitHub.com Fallback** ⚠️