🎨
UVC
  • Introduction
  • Installation
    • Installing in New Project
    • Installing in Existing Project - SCK
    • Installing in Existing Project - MCK
  • Space Combat Kit Tour
  • Mech Combat Kit Tour
  • Player Setup
  • Vehicle Framework
    • Game Agents
    • Vehicles
    • Modules
      • Module Mounts
      • Modules
      • Module Types
      • Module Attachments
      • Display Module On UI
      • Module Managers
  • Input
    • General Input
    • Vehicle Input
    • Rewired Integration
  • Player/AI
  • Spaceships
    • Speed UI
    • Space Fighters
    • Capital Ships
  • Mechs
    • Speed UI
  • Vehicle Control Animations
  • Character Enter/Exit
  • Camera
    • Camera Setup
    • Vehicle Setup
    • Secondary Cameras
    • Death Camera
  • Weapons
    • Framework
      • Triggerables System
      • Weapon System
    • Vehicle Setup
      • Vehicle Weapons
      • Cursor Aiming
    • Projectile Weapons
    • Beam Weapons
    • Missile Weapons
    • Resource Handling (Ammo/Heat)
    • Turrets
    • HUD Weapon Info
    • Health Modifier Volumes
  • Radar
    • Radar Setup
    • Target Setup
    • Target Selectors
    • Trackable Types
    • Improving Radar Performance
    • Target Notification
    • Radar Audio
  • Health
    • Health Framework
      • Health
      • Damageable
      • Damage Receiver
      • Health Modifier
      • Health Types
      • Health Modifier Types
      • Surface Types
    • Vehicle Setup
    • Damageable Object Setup
    • Detonators
    • Health Recharge
    • Health UI
    • Energy Shield
    • Damageable Module Linkers
  • HUD
    • HUD Basics
    • HUD Manager Setup
    • Custom HUD Components
    • HUD Module Display
    • Camera View Management
    • HUD Cursor / Reticle
    • Weapon UI
    • Resource Container UI
    • 2D Radar
    • 3D Radar
    • Target Boxes
    • Target Holograms
    • Minimaps
    • HUD Distance Lookup
  • Loadout
  • AI - Space Combat Kit
    • AI Setup
    • AI Spaceship Behaviours
  • AI - Mech Combat Kit
  • Game States
  • Teams
  • Floating Origin
  • Object Pooling
  • Menus
    • Creating Menus
    • Button Controllers
  • Rumbles
  • Rigidbody Characters [WIP]
  • Utilities [WIP]
    • Object Triggers
    • Shadow Caster Doubles
    • Gimbals
    • Game State Post Process Enabler
  • Objectives
  • Resources System
    • Resource Containers
    • Resource Handlers
    • Resource Container Triggers
    • Module/Vehicle Resource Usage
    • UI
  • Cutscenes
  • URP Upgrading
Powered by GitBook
On this page
  • Creating AI
  • Behaviour Selector
  • Behaviours

Was this helpful?

  1. AI - Space Combat Kit

AI Setup

In the Space Combat Kit, two AI prefabs have been provided:

  • EnemyPilot_SpaceFighter - for space fighter AI

  • EnemyPilot_CapitalShip - for capital ship AI

To use them:

  1. Drag the prefab into the scene

  2. Open the Game Agent inspector and set the Starting Vehicle field to some ship that exists in the scene

Creating AI

To set up a new spaceship AI:

  1. Create a new game object

  2. Add a Game Agent component and make sure Is Player is unchecked in the inspector

  3. Add a new game object as a child and add a Behaviour Selector component to it

  4. For each spaceship behaviour you want to add, add the component to a child gameobject and drag it into the Behaviours list in the inspector of the Behaviour Selector component.

Behaviour Selector

The primary vehicle input script for spaceship AI is the Behaviour Selector.

This component stores a list of spaceship behaviours, and each frame, tries to run them, starting from the first behaviour in the list. As soon as a behaviour runs successfully, the selector stops until the next frame.

That means that the first behaviour in the list has priority, and the last behaviour has the last priority, and as long as higher priority behaviours are running, lower priority behaviours will not run.

So for example, the space fighter enemy prefab has the following behaviours added to the Behaviour Selector component:

  1. Obstacle Avoidance

  2. Combat

  3. Patrol

This means that:

  1. If Obstacle Avoidance is running (there's an obstacle) other behaviours won't run.

  2. If no obstacles are found, obstacle avoidance doesn't run, selector moves to Combat.

  3. If no targets are around, Combat doesn't run, so selector moves to Patrol

Thus you want to add behaviours in order of priority to the list.

Behaviours

Currently, the following spaceship behaviours have been added to the Space Combat Kit:

  • Spaceship Move To Position Behaviour

  • Spaceship Formation Behaviour

  • Spaceship Patrol Behaviour

  • Spaceship Evade Behaviour

  • Spaceship Attack Behaviour

  • Spaceship Combat Behaviour

  • Obstacle Avoidance Behaviour

Adding Behaviours

To add behaviours to your AI:

  1. Add components that extend the AI Spaceship Behaviour base class under the AI's behaviour selector

  2. Drag them into the Behaviour Selector's Behaviours list in order of priority (first = highest priority)

Creating Behaviours

To create your own spaceship behaviour:

  1. Create a new script that extends the AI Spaceship Behaviour base class.

  2. Override the Behaviour Update function to add your own code.

  3. In your own code, call the Steer Toward and Move Toward functions and pass the target position to make the ship steer and move toward it.

For example:

public class MySpaceshipBehaviour : AISpaceshipBehaviour
{
    public override bool BehaviourUpdate
    {
        if (!base.BehaviourUpdate()) return false;
        
        SteerToward(somePosition);
        MoveToward(somePosition);
    }
}

PreviousAI - Space Combat KitNextAI Spaceship Behaviours

Last updated 2 years ago

Was this helpful?