OrbitState - jimdroberts/FishMMO GitHub Wiki

Description

AI state for orbiting around a target. Handles movement, rotation, and state transitions for NPCs.


API Access

Fields

  • public float OrbitRadius

    Radius of the orbit around the target.

  • public float OrbitSpeed

    Speed at which the AI orbits around the target.

  • public float RotationSpeed

    Speed at which the AI rotates to face the target.

  • private float currentAngle

    Current angle in the orbit (radians).

Methods

  • public override void Enter(AIController controller)

    Called when entering the Orbit state. Initializes orbit angle and checks for target. Parameters: - AIController controller: The AI controller.*

  • public override void Exit(AIController controller)

    Called when exiting the Orbit state. Can be used to stop movement or reset parameters. Parameters: - AIController controller: The AI controller.*

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

    Called every frame to update the Orbit state. Handles orbit movement, rotation, and state transitions. Parameters: - AIController controller: The AI controller. - float deltaTime: Frame time.*


Basic Usage

Setup

  1. Create a new OrbitState asset via the Unity Editor (Assets > Create > FishMMO > Character > NPC > AI > Orbit State).
  2. Assign the state to an AIController for NPCs that require orbiting behavior.
  3. Adjust OrbitRadius, OrbitSpeed, and RotationSpeed as needed for your NPC behavior.

Example

// Example 1: Assigning the Orbit state to an AI controller
AIController ai = ...;
OrbitState orbitState = ...;
ai.ChangeState(orbitState);

// Example 2: Customizing orbit parameters
orbitState.OrbitRadius = 12.0f;
orbitState.OrbitSpeed = 3.0f;
orbitState.RotationSpeed = 8.0f;

Best Practices

  • Adjust OrbitRadius, OrbitSpeed, and RotationSpeed for different NPC types and behaviors.
  • Use polar coordinates to calculate smooth orbiting movement around the target.
  • Transition to appropriate states when the target is lost or randomization is triggered.
  • Document custom AI state logic for maintainability and clarity.
⚠️ **GitHub.com Fallback** ⚠️