OrbitState - jimdroberts/FishMMO GitHub Wiki
AI state for orbiting around a target. Handles movement, rotation, and state transitions for NPCs.
-
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).
-
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.*
- Create a new OrbitState asset via the Unity Editor (Assets > Create > FishMMO > Character > NPC > AI > Orbit State).
- Assign the state to an AIController for NPCs that require orbiting behavior.
- Adjust OrbitRadius, OrbitSpeed, and RotationSpeed as needed for your NPC behavior.
// 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;
- 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.