Class PetIdleState
A pet's out-of-combat state: heel near its owner, hold position on a Stay order, and enter combat when the pet's PetStance says it should.
[CreateAssetMenu(fileName = "New AI Pet Idle State", menuName = "FishMMO/Character/NPC/AI/Pet Idle State", order = 0)]
public class PetIdleState : BaseAIState, ICachedObject
- Inheritance
-
ObjectScriptableObjectPetIdleState
- Implements
- Inherited Members
-
ScriptableObject.SetDirty()ScriptableObject.CreateInstance<T>()Object.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
Following is driven off Home, which for a pet resolves to its owner's live position. It is deliberately not driven off Target — that means "the thing I am fighting" everywhere else in the AI, and the two meanings cannot share one field. They used to, and the result was a pet that stopped following its owner permanently the moment a fight ended, because ending a fight clears the target.
Not getting stuck is the other half of this state's job. A pet chases a player who runs through doorways, off ledges and around props, so it meets every NavMesh failure mode there is. Three layers handle it: a follow band so the pet is not repathing every tick, a stuck detector that walks it out of geometry, and a distance leash that teleports it when the owner has simply gone somewhere the pet cannot walk.
Fields
AggressiveSweepRate
How often (seconds) an aggressive pet sweeps for something to attack.
[Header("Engagement")]
[Tooltip("Seconds between hostile sweeps while in the Aggressive stance.")]
public float AggressiveSweepRate
Field Value
FollowDistance
How far the pet is allowed to drift from its owner before it moves back.
[Header("Following")]
[Tooltip("Distance from the owner at which the pet starts catching up.")]
public float FollowDistance
Field Value
FollowHysteresis
How far inside FollowDistance the pet closes before it stops again.
[Tooltip("Extra distance the pet closes past the follow distance before stopping.")]
public float FollowHysteresis
Field Value
Remarks
Without a band, a pet sitting exactly at the follow distance flickers between "close enough, stop" and "too far, move" on alternating ticks, which reads as a stutter and repaths constantly.
StuckTeleportSeconds
Seconds the pet may be wedged before it teleports to its owner.
[Tooltip("Seconds wedged on geometry before the pet teleports to its owner. 0 disables.")]
public float StuckTeleportSeconds
Field Value
Remarks
The distance leash alone is not enough: a pet jammed behind a crate five metres from its owner is stuck indefinitely without ever exceeding TeleportDistance. This is the escape hatch for that case, and it only fires after the generic recovery has already tried to walk the pet out.
TeleportDistance
If the pet ends up further than this from its owner, it teleports rather than walking.
[Tooltip("Distance from the owner beyond which the pet teleports instead of walking. 0 disables.")]
public float TeleportDistance
Field Value
Remarks
Covers what pathing cannot: the owner mounting and riding away, a teleport, a zone transition, or a pet left on the wrong side of a chasm.
Methods
Enter(AIController)
Prepares the pet to heel. Run speed, because it has to be able to catch a sprinting owner.
public override void Enter(AIController controller)
Parameters
controllerAIControllerThe AI controller.
Exit(AIController)
Called when exiting the Pet Idle state.
public override void Exit(AIController controller)
Parameters
controllerAIControllerThe AI controller.
UpdateState(AIController, float)
Heels, holds, or engages depending on the pet's orders.
public override void UpdateState(AIController controller, float deltaTime)
Parameters
controllerAIControllerThe AI controller.
deltaTimefloatSeconds since the previous AI tick.