Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Making your creature aggressive

LeeTwentyThree edited this page Sep 22, 2021 · 16 revisions

Initial remarks

So, you want to make a new aggressive fish, huh? A shark? A leviathan? Fun fact: Mods with aggressive leviathans seem to get a disproportionate amount of downloads compared to those without. Unfortunately, that also means peaceful fish go underappreciated. If placed correctly and given unique gimmicks, custom aggressive fauna can have a massive influence on the gameplay. So, let's get into starting on this.

CreatureAsset properties/methods related to aggression

Below I will list properties you should override and methods you should call in your CreatureAsset that relate to aggression.


public virtual bool EnableAggression { get; }

You must override this property and set it to true if you want aggression to work correctly on this creature. It is only used internally by ECC and not directly by Subnautica, but still remember to set it to true!

Remarks:

  • This property is from the beginning of ECC. Looking back on it, this is not necessary, and is just a relic of the past. It may become obsolete at some point.
  • On an internal level, all this Property is used for is to check whether the AttackSettings and AggressivenessToSmallVehicles Properties will be used or not.

protected AggressiveWhenSeeTarget MakeAggressiveTo(float maxRange, int maxSearchRings, EcoTargetType ecoTarget, float hungerThreshold, float aggressionSpeed)

Call this method as many times as needed in your "AddCustomBehaviour" implementation. On the internal level, each call adds an AggressiveWhenSeeTarget component with values adjusted based on the given parameters.

Parameters:

  • maxRange: The max range in meters that this Creature can target creatures of this EcoTargetType.
  • maxSearchRings: Search rings are a rather arbitrary thing, but they tie in with the maxRange. Most smaller sharks use 1 search ring, while Reaper Leviathans and Sea Dragons use 3.
  • ecoTarget: This Creature will only target creatures with the specified EcoTargetType.
  • hungerThreshold: This creature will only look for creatures of the specified EcoTargetType if this Creature's hunger stat is above that value. Set to 0 for it to always attack.
  • aggressionSpeed: The rate at which this Creature's aggressive stat increases per second while it has its eyes on a target.

Remarks:

  • If you want more fine control over your Creature's targeting, do not hesitate to create your own Aggressiveness component.
  • Most Creatures call method multiple times, so they can target different EcoTargetTypes.
  • Some of the EcoTargetType values may be confusing.
    • EcoTargetType.Small includes most small fish.
    • EcoTargetType.Medium includes Rabbit Rays and Peepers.
    • EcoTargetType.Shark includes most aggressive fauna besides leviathans, and the player for reasons unknown
  • Reaper Leviathans have an aggressionSpeed of 2 and stalkers have an aggresionSpeed of 1. Oddly enough the Sea Dragon is only 1 per second.

public virtual AttackLastTargetSettings AttackSettings { get; }

A property that defines how this creature will attack things. You should override this so you can have fine control over how your creature works.


public virtual SmallVehicleAggressivenessSettings AggressivenessToSmallVehicles { get; }

A property that defines the aggressiveness to small vehicles. This is very simple and the struct only takes in two parameters.

Remarks:

  • The Creature will target any vehicle in range of MaxRange and increase its aggression stat at a rate which is defined by the Aggression parameter of the struct
  • Internally, adds the AggressiveToPilotingVehicle component to the creature
    • Only if the aggression value is greater than 0, otherwise there is no point.

Example

Below an example of the implementation of a creature that hunts the player, sharks, and small vehicles is shown. The code may look different if Properties were added/made obsolete since the creation of this guide.

...

    public class ExampleShark : CreatureAsset
    {
        ...

        public override bool EnableAggression => true;

        public override SmallVehicleAggressivenessSettings AggressivenessToSmallVehicles => new SmallVehicleAggressivenessSettings(0.5f, 25f); // aggressive to seamoths within 25 meters of the creature

        ...

        public override void AddCustomBehaviour(CreatureComponents components)
        {
            MakeAggressiveTo(25f, 1, EcoTargetType.Shark, 0.1f, 0.67f); // aggressive to sharks (which include the player) within 25 meters, if the hunger is greater than 0.1, and increases aggression at a rate of 0.67 points per second
        }

        ...
    }