All Classes Namespaces Functions Variables Enumerations Enumerator Properties
plyGame.NPCController Class Reference

The Default NPC Controller and AI More...

Inherits plyGame.CharacterControllerBase.

Public Types

enum  IdleMode { IdleMode.Stay, IdleMode.Wander, IdleMode.Patrol, IdleMode.Follow }
 What the NPC does while not using Skills More...
 
enum  WanderArea { Circular, Rectangular }
 
- Public Types inherited from plyGame.CharacterControllerBase
enum  ValidInteractTargets { FriendlyActor = (1 << 0), NeutralActor = (1 << 1), HostileActor = (1 << 2), RPGObject = (1 << 3) }
 
- Public Types inherited from plyGame.Targetable
enum  Type { Type.Character = 1, Type.Object = 2, Type.Item = 4, Type.Unknown = 1024 }
 The targetable types More...
 

Public Member Functions

override bool RequestFaceDirection (Vector3 direction, float delayAfter)
 
override bool RequestMoveTo (Vector3 position, bool useFasterMovement)
 
override float MoveSpeed ()
 
override bool Grounded ()
 
override Vector3 Velocity ()
 
override Vector3 Movement ()
 
override void OnDeath ()
 
override void Stop ()
 
void SetPatrolPath (WaypointPath p, int pointOnPath)
 
int LastDetectedTotal ()
 Return the total number of characters that where detected in the last detection action. More...
 
CharacterControllerBase GetDetected (int idx)
 Return the detected character that is at position 'idx' in the list of detected characters. The characters are sorted from closest to furthest from the NPC. More...
 
float GetDetectedDistance (int idx)
 Return distance the detected character, at index idx, is from the NPC The characters are sorted from closest to furthest from the NPC. Return -1 if index is invalid. More...
 
- Public Member Functions inherited from plyGame.CharacterControllerBase
void Save (string key)
 
void Load (string key)
 
void DeleteSaveData (string key)
 
void DisablePersistence ()
 
void SelectTarget (GameObject go)
 Called when a target is selected. et the selected target. If null or passed object is not a Targetable, then the selected target will be cleared. You should call base.SelectTarget() if you override this. More...
 
virtual void SelectTarget (Targetable t)
 Called when a target is selected. If null then the selected target will be cleared. You should call base.SelectTarget() if you override this. More...
 
virtual void ClearTarget ()
 Called when the target is cleared. You should call base.ClearTarget() if you override this. More...
 
virtual void SetTargetInteract (GameObject go)
 The gameObject as target interact. The character will try to move to it and face it before the Interact related events are triggered. More...
 
virtual void SetTargetInteract (Targetable t)
 The character will try to move to it and face it before the Interact related events are triggered. More...
 
virtual void StopInteract ()
 Trigger event on currently active interact More...
 
override Type TargetableType ()
 You will not need to override this in a base class as it already returns Type.Character. More...
 
override object DataObject ()
 You will not need to override this in a base class as it already returns actor (as data object). More...
 
virtual bool MovementControlAllowed ()
 Return true if the character may accept input to generate movement More...
 
virtual bool IsPlayer ()
 Derived class must override this to tell plyGame if this controller (Character) is a player character controller or non-player character (NPC). More...
 
virtual void EnableControl (bool en)
 Enable or Disable Input (or AI in case of NPCs). Call base.EnableControl() if you override this. More...
 
virtual void SetMoveSpeed (float speed)
 Set the movement speed of the character More...
 
virtual void SetTurnSpeed (float speed)
 Set the turn speed of the character More...
 
virtual float TurnSpeed ()
 Return the current turn speed being used. This defaults to returning turnSpeed but some controllers might override this if they have other movement speed types, for example running during a chase. More...
 
virtual bool RequestLookAt (Vector3 position, float delayAfter)
 Turn the character to face the target location (position). Return false if this character controller do not accept requests to turn. Actor uses this to ask the character to look in a direction to perform skill. The delayAfter determine how long the character will face the target direction, after reaching it and before returning to viewing in direction is is moving (if moving). More...
 
virtual void StopAll ()
 Ask character to stop. Removing queued targets and stop moving. More...
 
- Public Member Functions inherited from plyGame.Targetable
virtual bool MustFaceToInteract ()
 Override to to specify when facing the object is not needed to interact with it. Default is True. More...
 

Public Attributes

float runSpeed = 6f
 The run speed used when chasing something - to get into range faster.
 
float thinkInterval = 1f
 How often the 'AI Think' event is called.
 
IdleMode idleMode = IdleMode.Stay
 What the NPC does while not using Skills.
 
WanderArea wanderArea = WanderArea.Circular
 Type of wander area.
 
float wanderRadius = 10f
 [IdleMode.Wander] Radius around spawn point. With WanderArea.Rectangular this is angle of rectangle
 
Vector2 wanderWH = Vector2.one
 [IdleMode.Wander] Width & Height of wander area when WanderArea.Rectangular
 
float wanderDelayMin = 0.5f
 [IdleMode.Wander] Min time, in Randomiser, to wait before choosing a new spot to move to
 
float wanderDelayMax = 2.0f
 [IdleMode.Wander] Max time, in Randomiser, to wait before choosing a new spot to move to
 
WaypointPath path
 [IdleMode.Patrol] Path to follow
 
Transform followObject
 [IdleMode.Follow] Object to follow around
 
float minFollowDistance = 5f
 Do not get too close.
 
float maxFollowDistance = 10f
 Get closer when too far.
 
bool canDetectPlayer = false
 Must be turned on to detect the player. For performance, turn this off if the NPC to not have to detect the player.
 
bool canDetectNPCs = false
 Must be turned on to detect other NPCs. For performance, turn this off if the NPC will never attack other NPCs.
 
StatusTowardsOther whenStatusTowardsPlayer = StatusTowardsOther.Hostile
 Will only detect the player if status towards player is this or higher.
 
StatusTowardsOther whenStatusTowardNPC = StatusTowardsOther.Hostile
 Will only do detect a target NPC if the status of the factions of this NPC is this or higher towards the faction(s) the target NPC is in.
 
bool ignoreEssentialActor = true
 Ignore detection of an Actor that is set to be essential.
 
float detectionTimeout = 1f
 How many seconds to wait before attempting the next detection.
 
bool skipIfEngaged = true
 Do not run detection if it has a target.
 
bool autoEngageClosest = true
 Should closest detected be automatically set as targeted? This will happen AFTER the 'On Detect Characters' Event, if set True.
 
float detection360Distance = 5f
 The radius used to detect the Player or other NPCs around this NPC.
 
float detectionForwardDistance = 8f
 The distance in direction the NPC is facing (in combination with detectionForwardAngle), used to detect the Player and other NPCs.
 
float detectionForwardAngle = 30f
 The angle/ range in direction the NPC is facing (in combination with detectionForwardDistance), used to detect the Player or other NPCs.
 
LayerMask detectionObstacleMask = (1 << GameGlobal.LayerMapping.Floor)
 What is considered in way of detecting.
 
LayerMask detectionFwObstacleMask = (1 << GameGlobal.LayerMapping.Floor | 1 << GameGlobal.LayerMapping.Wall)
 What is considered in way of detecting (for forward detection)
 
float obstacleCheckOffsetY = 1f
 Height at which to cast ray from (eye level)
 
float engagedMinDistance = 2f
 Set this to the minimum distance the NPC can be from its engaged target. NPC will run closed if needed and not executing a skill.
 
float engagedMaxDistance = 5f
 Set this to the maximum distance the NPC can be from its engaged target. NPC will move away from target if closer than this to target and not executing a skill.
 
float disengageDistanceHome = 35f
 Disengage the selectedTarget when further than this distance from SpawnPoint, Follow Target, or Patrolled Path. Set to 0 to disable this.
 
float disengageDistanceTarget = 10f
 also check if at least this far from target, else stay on target
 
- Public Attributes inherited from plyGame.CharacterControllerBase
bool persistenceOn = false
 
bool persistSpeed = true
 
float moveSpeed = 5.0f
 How fast the character should be moving when moving (or max speed it can reach)
 
float turnSpeed = 10.0f
 How fast the character can turn when turning (or max turn speed)
 
float maxInteractDistance = 2f
 max distance this character can be from something to interact with it
 
ValidInteractTargets validInteractTarget = (ValidInteractTargets.FriendlyActor | ValidInteractTargets.NeutralActor | ValidInteractTargets.RPGObject)
 
ResultCallback onJump
 Assign to this a delegate to respond to the character jumping. LegacyAnimControl for example hooks into this so it knows when to play the jump clip.
 
GeneralCallback onDeath
 Assign to this a delegate to respond to the character dying. LegacyAnimControl for example hooks into this so it knows when to play the death clip.
 
- Public Attributes inherited from plyGame.Targetable
GeneralCallback onDestroy
 Assign to this a delegate to respond to this object being destroyed.
 

Protected Member Functions

void Reset ()
 
new void Awake ()
 
new void Start ()
 
void Update ()
 
- Protected Member Functions inherited from plyGame.CharacterControllerBase
void Awake ()
 
void Start ()
 
void LateUpdate ()
 
- Protected Member Functions inherited from plyGame.Targetable
void OnDestroy ()
 

Properties

Vector3 spawnLocation [get, set]
 
NPCMoveBase navi [get, set]
 
SpawnPoint spawnPoint [get, set]
 
int spawnGroupIdx [get, set]
 
- Properties inherited from plyGame.CharacterControllerBase
Targetable selectedTarget [get, set]
 This character's currently selected Targetable object. For player controllers this would be what the player clicked on (characters, items and objects) last and for NPCs this would be what the AI selected (only other characters) More...
 
Targetable queuedInteract [get, set]
 The object queued to be interacted with once character is in range and facing it. More...
 
bool Interacting [get]
 True while the character is "interacting" with something. StopInteract() must be called to stop it. More...
 
Actor actor [get, set]
 The Actor component of the character More...
 
Transform _tr [get, set]
 The Transform component of the character More...
 
bool hint_DoNotMove [get, set]
 If set then the character should not move. Normally set by actor when a skill being used do not allow movement. More...
 
bool controlEnabled [get, set]
 Is control of the character enabled? Player characters should not accept input and an NPC's I should be off when this is false. More...
 

Detailed Description

The Default NPC Controller and AI

Member Enumeration Documentation

What the NPC does while not using Skills

Enumerator
Stay 

Do not move around.

Wander 

Wander in specified radius round spawn point.

Patrol 

Follow a specified path.

Follow 

Follow a specified object.

Member Function Documentation

CharacterControllerBase plyGame.NPCController.GetDetected ( int  idx)

Return the detected character that is at position 'idx' in the list of detected characters. The characters are sorted from closest to furthest from the NPC.

float plyGame.NPCController.GetDetectedDistance ( int  idx)

Return distance the detected character, at index idx, is from the NPC The characters are sorted from closest to furthest from the NPC. Return -1 if index is invalid.

int plyGame.NPCController.LastDetectedTotal ( )

Return the total number of characters that where detected in the last detection action.