Class RetreatState
Moves the NPC away from its target until a safe distance is reached, then disengages.
[CreateAssetMenu(fileName = "New AI Retreat State", menuName = "FishMMO/Character/NPC/AI/Retreat State", order = 0)]
public class RetreatState : BaseAIState, ICachedObject
- Inheritance
-
ObjectScriptableObjectRetreatState
- 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
Used both as the flee state for a Pathetic or Cautious personality and as a caster's emergency-retreat hand-off. Enable KeepsCombatTarget on assets of this type: the retreat direction is computed from the target, so clearing it on the way in would leave the NPC with no idea which way to run.
Fleeing is the movement most likely to run out of room — the NPC is by definition being pushed toward whatever is behind it — so every step of it is bounded. A cornered NPC that cannot retreat gives up and re-engages rather than standing against a wall being hit while a "retreating" state reports success.
Fields
MaxRetreatSeconds
Seconds the NPC will keep trying to retreat before accepting that it cannot.
[Tooltip("Seconds spent retreating before giving up. 0 = retreat until safe.")]
public float MaxRetreatSeconds
Field Value
RetreatDistance
How far the NPC moves away from its target on each retreat leg.
public float RetreatDistance
Field Value
SafeDistance
Distance from the target at which the NPC stops retreating.
public float SafeDistance
Field Value
Methods
Enter(AIController)
Picks the first retreat destination.
public override void Enter(AIController controller)
Parameters
controllerAIControllerThe AI controller managing this NPC.
Exit(AIController)
Called when the state is exited.
public override void Exit(AIController controller)
Parameters
controllerAIControllerThe AI controller managing this NPC.
UpdateState(AIController, float)
Keeps backing away until safe, cornered, or out of patience.
public override void UpdateState(AIController controller, float deltaTime)
Parameters
controllerAIControllerThe AI controller managing this NPC.
deltaTimefloatSeconds since the previous AI tick.