Adventure Creator  1.79.1
An adventure game toolkit for Unity, by Chris Burton, ICEBOX Studios 2013-2022
AC.NPC Class Reference
Inheritance diagram for AC.NPC:
AC.Char AC.ITranslatable AC.Player

Public Member Functions

override void _Update ()
 
void StopFollowing ()
 
void FollowAssign (Char _followTarget, bool _followTargetIsPlayer, float _followFrequency, float _followDistance, float _followDistanceMax, bool _faceWhenIdle=false, bool _followRandomDirection=true, bool _followAcrossScenes=false)
 Assigns a new target (NPC or Player) to start following. More...
 
NPCData SaveData (NPCData npcData)
 Updates a NPCData class with its own variables that need saving. More...
 
void LoadData (NPCData data)
 Updates its own variables from a NPCData class. More...
 
AC.Char GetFollowTarget ()
 Gets the character that the NPC is currently following, if any. More...
 
void HideFromView (Player player=null)
 Moves the NPC out of the view by basically teleporting them very far away. More...
 
override string ToString ()
 
void Convert ()
 
- Public Member Functions inherited from AC.Char
virtual bool IsCapableOfJumping ()
 
virtual bool IsActivePlayer ()
 
virtual void _LateUpdate ()
 
virtual void _FixedUpdate ()
 
void RecalculateActivePathfind ()
 
bool AccurateDestination ()
 Checks if the character should attempt to be as accurate as possible when moving to a destination. More...
 
void Teleport (Vector3 _position, bool recalculateActivePathFind=false)
 Teleports the character. The message 'OnTeleport' will be sent to the character's GameObject after the position is set. More...
 
void SetRotation (Quaternion _rotation)
 Instantly rotates the character More...
 
void SetRotation (float angle)
 Instantly rotates the Player More...
 
void StopTurning ()
 
virtual void StopTankTurning ()
 
float GetAngleDifference ()
 Gets the difference between the character's current facing angle, and the angle they wish to face. More...
 
void SetLookDirection (Vector3 _direction, bool isInstant)
 Sets the intended direction to face. More...
 
void SetMoveDirection (Vector3 _direction, bool useSmoothing=false)
 Moves the character in a particular direction. More...
 
void SetMoveDirectionAsForward ()
 
void SetMoveDirectionAsBackward ()
 
Animation GetAnimation ()
 Gets the character's Animation component. More...
 
Animator GetAnimator ()
 Gets the character's Animator component. An Animator placed on the spriteChild GameObject will be given priority. More...
 
void ResetAnimator ()
 
Vector3 GetMoveDirection ()
 Gets the direction that the character is moving in. More...
 
bool WillStopAtNextNode ()
 Checks if the character is pathfinding, and the next node on the path will be their intended destination More...
 
bool IsPathfinding ()
 Checks if the character is currently pathfinding to a pre-determined destination More...
 
void EndPath (Paths optionalPath, bool stopTurningToo=true)
 Stops the character from moving along the current Paths object. More...
 
void StartDecelerating ()
 
virtual void EndPath ()
 
void ResumeLastPath ()
 
void ForgetLastPath ()
 
void Halt (bool haltTurning=true)
 Stops the character moving. More...
 
void ForceIdle ()
 
bool IsTurningBeforeWalking ()
 Checks if the character is spot-turning before making their move. isTurningBeforeWalking must be True for this to ever be the case. More...
 
void SetPath (Paths pathOb, PathSpeed _speed)
 Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined. More...
 
void SetPath (Paths pathOb)
 Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined. More...
 
void SetPath (Paths pathOb, int _targetNode, int _prevNode)
 Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined. More...
 
void SetPath (Paths pathOb, int _targetNode, int _prevNode, bool affectY)
 Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined. More...
 
Paths GetPath ()
 Gets the current Paths object that the character is moving along. If the character is pathfinding, the Paths component on the character's root will be returned. More...
 
int GetTargetNode ()
 
int GetPreviousNode ()
 
Paths GetLastPath ()
 
void MoveToPoint (Vector3 point, bool run=false, bool usePathfinding=false)
 Moves towards a point in the scene. More...
 
void MoveAlongPoints (Vector3[] pointData, bool run, bool allowUpdating=true)
 Moves along a series of points in the scene. More...
 
void ResetBaseClips ()
 
float GetSpriteAngle ()
 Gets the angle that a 2D character's sprite is facing, relative to the root. More...
 
string GetSpriteDirection (bool ignoreFrameFlipping=false)
 Gets the suffix to add to sprite animations that account for the facing direction - e.g. "Walk" -> "Walk_DR". More...
 
int GetSpriteDirectionInt (bool ignoreFrameFlipping=false)
 Gets the direction that a 2D character is facing (Down = 0, Left = 1, Right = 2, Up = 3, DownLeft = 4, DownRight = 5, UpLeft = 6, UpRight = 7) More...
 
void SetSpriteDirection (CharDirection direction)
 Locks a 2D character's sprite to face a particular direction. More...
 
void ResetAnimationEngine ()
 
float FlattenSpriteAngle (float angle, AngleSnapping _angleSnapping)
 Snaps a given angle to the nearest 90 or 45 degrees More...
 
void SetSorting (int order)
 Locks the Renderer's sortingOrder. More...
 
void SetSorting (string layer)
 Locks the Renderer's sorting layer. More...
 
void ReleaseSorting ()
 
float GetMoveSpeed (bool reduceNonFacing=false)
 Gets the current movement speed. More...
 
virtual void SetHeadTurnTarget (Transform _headTurnTarget, Vector3 _headTurnTargetOffset, bool isInstant, HeadFacing _headFacing=HeadFacing.Manual)
 Controls the head-facing position. More...
 
void ClearHeadTurnTarget (bool isInstant, HeadFacing _headFacing)
 Ceases a particular type of head-facing. More...
 
void ClearHeadTurnTarget (bool isInstant)
 Stops the head from facing a fixed point. More...
 
void SnapHeadMovement ()
 
bool IsMovingHead ()
 Checks if the head is rotating to face its target, but has not yet reached it. More...
 
Shapeable GetShapeable ()
 Gets the Shapeable script component attached to the GameObject's root or child. More...
 
Vector3 GetHeadTurnTarget ()
 Gets the position of where the character's head is facing towards. More...
 
Transform GetHandTransform (Hand hand)
 
bool HoldObject (GameObject objectToHold, Hand hand)
 Parents an object to the character's hand More...
 
void ReleaseHeldObjects (bool delete)
 
void ReleaseHeldObject (Hand hand, bool delete)
 
Vector3 GetSpeechWorldPosition ()
 Gets the position of the top of the character, in world-space. More...
 
Vector2 GetSpeechScreenPosition (bool keepWithinScreen=true)
 Gets the position of the top of the character, in screen-space. More...
 
void StartLipSync (List< LipSyncShape > _lipSyncShapes)
 Begins a lip-syncing animation based on a series of LipSyncShapes. More...
 
int GetLipSyncFrame ()
 Gets the current lip-sync frame. More...
 
float GetLipSyncNormalised ()
 Gets the current lip-sync frame, as a fraction of the total number of phoneme frames. More...
 
bool LipSyncGameObject ()
 Checks if the character is playing a lip-sync animation that affects the GameObject. More...
 
void StopSpeaking ()
 
int GetExpressionID (string expressionLabel)
 Gets the ID number of the Expression that has a specific label. More...
 
int GetExpressionID ()
 Gets the ID number of the currently-active Expression. More...
 
void ClearExpression ()
 Clears the current Expression so that the default portrait icon is used. More...
 
void SetExpression (int ID)
 Changes the active Expression. More...
 
void SetExpression (string _name)
 Changes the active Expression. More...
 
CursorIconBase GetPortrait ()
 Gets the active portrait that's displayed in a MenuGraphic element when the character speaks. The portrait can change if an Expression has been defined. More...
 
bool IsGrounded (bool reportError=false)
 Checks if the character (if 3D) is in contact with the ground. More...
 
MotionControl GetMotionControl ()
 Gets the extent to which motion is controlled by the character script (Automatic, JustTurning, Manual). More...
 
Vector3 GetTargetPosition (bool wantFinalDestination=false)
 Gets the character's destination when walking along a path. More...
 
Quaternion GetTargetRotation ()
 Gets the character's target rotation. More...
 
Quaternion GetFrameRotation ()
 Gets the character's calculated rotation for this frame. This is not the same as GetTargetRotation, which is the 'final' rotation, but instead the rotation that a smoothly-rotated character should take. More...
 
AnimEngine GetAnimEngine ()
 Gets the character's AnimEngine ScriptableObject. More...
 
void SetAnimEngine (AnimationEngine _animationEngine, string customClassName="")
 Sets the character's AnimEngine ScriptableObject. More...
 
float GetHeightChange ()
 Gets the character's change in height over the last frame. More...
 
bool IsReversing ()
 Checks if the character is moving backwards. More...
 
virtual float GetTurnFloat ()
 Gets the rate at which the character is turning (negative values used when turning anti-clockwise). More...
 
bool IsTurning ()
 Checks if the character is turning. More...
 
bool IsTurning (float maxAngleThreshold)
 Checks if the character is turning. More...
 
bool IsMovingAlongPath ()
 Checks if the character is moving along a path. More...
 
string GetName (int languageNumber=0)
 Gets the Character's current display name. More...
 
void SetName (string newName, int _lineID)
 Renames the Character mid-game. More...
 
void SetSpeechVolume (float volume)
 Updates the volume level of the Character's speech audio. More...
 
Speech GetCurrentSpeech ()
 Gets the character's current speech line More...
 
void OnEnterTimeline (PlayableDirector director, int trackIndex)
 Called whenever the character is bound to a Timeline track that's starting, and used to deactivate certain control components to allow them freedom. More...
 
void OnExitTimeline (PlayableDirector director, int trackIndex)
 Called whenever the character is bound to a Timeline track that's ending, and used to re-activate certain control components. More...
 
Sprite GetPortraitSprite ()
 Gets a Sprite based on the portrait graphic of the character. If lipsincing is enabled, the sprite will be based on the current phoneme. More...
 
string GetTranslatableString (int index)
 Gets the text to be translated, given its index. More...
 
int GetTranslationID (int index)
 Gets the translation ID of a given text index. More...
 
AC_TextType GetTranslationType (int index)
 Gets the translation type of a given text index. More...
 
void UpdateTranslatableString (int index, string updatedText)
 
int GetNumTranslatables ()
 Gets the maximum number of possible translatable texts. More...
 
bool HasExistingTranslation (int index)
 Checks if a given text index has already been assigned a unique translation ID. More...
 
void SetTranslationID (int index, int _lineID)
 Sets the translation ID of a given text index More...
 
string GetOwner (int index)
 Gets the name of the translatable text's owner. In the case of speech text, it is the name of the character. In the case of menu element text, it is the name of the menu element. More...
 
bool OwnerIsPlayer (int index)
 Checks if the translatable text's owner is a Player. This is necessary for speech lines, since multiple player prefabs can feasibly share the same line. More...
 
bool CanTranslate (int index)
 Checks if a given text index can and should be translated. More...
 
void SetTimelineHeadTurnOverride (Transform _timelineHeadTurnTarget, Vector3 _timelineHeadTurnTargetOffset, float _timelineHeadTurnWeight)
 
void ReleaseTimelineHeadTurnOverride ()
 

Public Attributes

bool moveOutOfPlayersWay = false
 
float minPlayerDistance = 1f
 
- Public Attributes inherited from AC.Char
CharState charState
 
AnimationEngine animationEngine = AnimationEngine.SpritesUnity
 
string customAnimationClass = ""
 
MotionControl motionControl = MotionControl.Automatic
 
TalkingAnimation talkingAnimation = TalkingAnimation.Standard
 
bool separateTalkingLayer = false
 
string speechLabel = ""
 
int lineID = -1
 
int displayLineID = -1
 
Color speechColor = Color.white
 
CursorIconBase portraitIcon = new CursorIconBase ()
 
bool useExpressions
 
List< Expressionexpressions = new List<Expression> ()
 
Transform speechMenuPlacement
 
bool mapExpressionsToShapeable = false
 
int expressionGroupID
 
float expressionTransitionTime = 0.2f
 
float lipSyncBlendShapeSpeedFactor = 1f
 
bool isLipSyncing = false
 
string phonemeParameter = ""
 
string phonemeNormalisedParameter = ""
 
int lipSyncGroupID
 
Transform leftHandBone
 
Transform rightHandBone
 
AnimationClip idleAnim
 
AnimationClip walkAnim
 
AnimationClip runAnim
 
AnimationClip talkAnim
 
AnimationClip turnLeftAnim
 
AnimationClip turnRightAnim
 
AnimationClip headLookLeftAnim
 
AnimationClip headLookRightAnim
 
AnimationClip headLookUpAnim
 
AnimationClip headLookDownAnim
 
Transform upperBodyBone
 
Transform leftArmBone
 
Transform rightArmBone
 
Transform neckBone
 
float animCrossfadeSpeed = 0.2f
 
int groundCheckLayerMask = 1
 
string moveSpeedParameter = "Speed"
 
string verticalMovementParameter = ""
 
string isGroundedParameter
 
string jumpParameter = ""
 
string turnParameter = ""
 
string talkParameter = "IsTalking"
 
string directionParameter = "Direction"
 
string angleParameter = "Angle"
 
string headYawParameter = ""
 
string headPitchParameter = ""
 
string expressionParameter = ""
 
float rootTurningFactor = 0f
 
int headLayer = 1
 
int mouthLayer = 2
 
Animator customAnimator
 
float turningAngleThreshold = 4f
 
bool listExpectedAnimations
 
bool turn2DCharactersIn3DSpace = true
 
Transform spriteChild
 
RotateSprite3D rotateSprite3D = RotateSprite3D.CameraFacingDirection
 
string idleAnimSprite = "idle"
 
string walkAnimSprite = "walk"
 
string runAnimSprite = "run"
 
string talkAnimSprite = "talk"
 
bool lockScale = false
 
float spriteScale = 1f
 
bool lockDirection = false
 
string spriteDirection = "D"
 
bool doDirections = true
 
bool crossfadeAnims = false
 
bool doDiagonals = false
 
AC_2DFrameFlipping frameFlipping = AC_2DFrameFlipping.None
 
bool flipCustomAnims = false
 
SpriteDirectionData _spriteDirectionData = null
 
AngleSnapping angleSnapping = AngleSnapping.None
 
float walkSpeedScale = 2f
 
float runSpeedScale = 6f
 
float reverseSpeedFactor = 1f
 
bool canRunInReverse = true
 
float turnSpeed = 7f
 
float acceleration = 6f
 
float deceleration = 0f
 
bool turnBeforeWalking = false
 
float runDistanceThreshold = 1f
 
bool antiGlideMode = false
 
bool retroPathfinding = false
 
bool ignoreGravity = false
 
bool freezeRigidbodyWhenIdle = false
 
bool useRigidbodyForMovement = true
 
bool useRigidbody2DForMovement = false
 
float simulatedMass = 1
 
float simulatedVerticalSpeed
 
bool doWallReduction = false
 
string wallLayer = "Default"
 
float wallDistance = 0.5f
 
bool wallReductionOnlyParameter = true
 
AudioClip walkSound
 
AudioClip runSound
 
AudioClip textScrollClip
 
Sound soundChild
 
AudioSource speechAudioSource
 
float headIKTurnFactor = 1f
 
float bodyIKTurnFactor = 0f
 
float eyesIKTurnFactor = 1f
 
Transform headTurnTarget
 
Vector3 headTurnTargetOffset
 
HeadFacing headFacing = HeadFacing.None
 
bool ikHeadTurning = false
 
float headTurnSpeed = 4f
 

Protected Member Functions

void Awake ()
 
void StayAwayFromPlayer ()
 
Vector3[] TryNavPoint (Vector3 _direction, float currentDistance)
 
void FollowUpdate ()
 
float FollowCheckDistance ()
 
void FollowCheckDistanceMax ()
 
void FollowStop ()
 
void TurnOn ()
 
void TurnOff ()
 
- Protected Member Functions inherited from AC.Char
virtual void _Awake ()
 
virtual void OnEnable ()
 
virtual void OnDisable ()
 
void BaseUpdate ()
 
void PathUpdate ()
 
float GetTargetSpeed ()
 
void AccurateAcc (float targetSpeed, bool canStop)
 
virtual void Accelerate ()
 
void SetLastPath (Paths _lastPathActivePath, int _lastPathTargetNode, int _lastPathPrevNode)
 
void ReverseDirection ()
 
int GetLastTargetNode ()
 
int GetLastPrevNode ()
 
string GetSpriteDirectionToSave ()
 
void PrepareSpriteChild (bool isTopDown, bool isUnity2D)
 
void UpdateFrameFlipping (bool ignoreLockDirectionOption=false)
 
void UpdateSpriteChild (bool isTopDown, bool isUnity2D)
 
void UpdateScale ()
 
virtual bool CanBeDirectControlled ()
 

Protected Attributes

bool isEvadingPlayer = false
 
Char followTarget = null
 
bool followTargetIsPlayer = false
 
float followFrequency = 0f
 
float followUpdateTimer = 0f
 
float followDistance = 0f
 
float followDistanceMed = 0f
 
float followDistanceMax = 0f
 
bool followFaceWhenIdle = false
 
bool followRandomDirection = false
 
bool followAcrossScenes = false
 
LayerMask LayerOn
 
LayerMask LayerOff
 
- Protected Attributes inherited from AC.Char
LerpUtils.FloatLerp moveSpeedLerp = new LerpUtils.FloatLerp ()
 
Quaternion newRotation
 
Transform _transform
 
Speech activeSpeech
 
float pathfindUpdateTime = 0f
 
bool isJumping = false
 
float turnFloat = 0f
 
Paths ownPath
 
AC_PathType lockedPathType
 
Rigidbody _rigidbody = null
 
Rigidbody2D _rigidbody2D = null
 
float originalGravityScale = 1f
 
Collider _collider = null
 
CharacterController _characterController
 
AudioSource audioSource
 
Paths activePath = null
 
float moveSpeed
 
Vector3 moveDirection
 
int targetNode = 0
 
bool pausePath = false
 
Vector3 lookDirection
 
int prevNode = 0
 
bool tankTurning = false
 
bool timelineHeadTurnOverride
 
Vector3 timelineHeadTurnTargetOffset
 
Transform timelineHeadTurnTarget
 
float timelineHeadTurnWeight
 

Additional Inherited Members

- Properties inherited from AC.Char
bool isRunning [get, set]
 
virtual bool IsPlayer [get]
 
float MoveSpeed [get]
 
Expression CurrentExpression [get]
 
bool AffectedByVerticalReduction [set]
 
Quaternion TransformRotation [get, set]
 
Vector3 TransformForward [get]
 
Vector3 TransformRight [get]
 
bool IsJumping [get]
 
SpriteDirectionData spriteDirectionData [get]
 
CharacterAnimationShot ActiveCharacterAnimationShot [get, set]
 
IKLimbController LeftHandIKController [get]
 
IKLimbController RightHandIKController [get]
 
Transform Transform [get, set]
 
bool isTalking [get]
 
float PathfindUpdateFrequency [get, set]
 

Detailed Description

Attaching this to a GameObject will make it an NPC, or Non-Player Character.

Member Function Documentation

◆ _Update()

override void AC.NPC._Update ( )
virtual

The NPC's "Update" function, called by StateHandler.

Reimplemented from AC.Char.

Reimplemented in AC.Player.

◆ Convert()

void AC.NPC.Convert ( )

Converts the character between an NPC and a Player.

◆ FollowAssign()

void AC.NPC.FollowAssign ( Char  _followTarget,
bool  _followTargetIsPlayer,
float  _followFrequency,
float  _followDistance,
float  _followDistanceMax,
bool  _faceWhenIdle = false,
bool  _followRandomDirection = true,
bool  _followAcrossScenes = false 
)

Assigns a new target (NPC or Player) to start following.

Parameters
_followTargetThe target to follow
_followTargetIsPlayerIf True, the NPC will follow the current Player, and _followTarget will be ignored
_followFrequencyThe frequency with which to follow the target
_followDistanceThe minimum distance to keep from the target
_followDistanceMaxThe maximum distance to keep from the target
_faceWhenIdleIf True, the NPC will face the target when idle
_followRandomDirectionIf True, the character will walk to points randomly in the target's vicinity, as opposed to directly towards them
_followAcrossScenesIf True, and if the character ia an inactive Player, and if they are following the active Player, they can follow the Player across scenes

◆ GetFollowTarget()

AC.Char AC.NPC.GetFollowTarget ( )

Gets the character that the NPC is currently following, if any.

Returns
The character that the NPC is currently following, if any.

◆ HideFromView()

void AC.NPC.HideFromView ( Player  player = null)

Moves the NPC out of the view by basically teleporting them very far away.

Parameters
playerThe Player they are moving out of the way for. This is only used to provide a log in the Console

◆ LoadData()

void AC.NPC.LoadData ( NPCData  data)

Updates its own variables from a NPCData class.

Parameters
dataThe NPCData class to load from

◆ SaveData()

NPCData AC.NPC.SaveData ( NPCData  npcData)

Updates a NPCData class with its own variables that need saving.

Parameters
npcDataThe original NPCData class
Returns
The updated NPCData class

◆ StopFollowing()

void AC.NPC.StopFollowing ( )

Stops the NPC from following the Player or another NPC.

Member Data Documentation

◆ minPlayerDistance

float AC.NPC.minPlayerDistance = 1f

The minimum distance to keep from the Player, if moveOutOfPlayersWay = True

◆ moveOutOfPlayersWay

bool AC.NPC.moveOutOfPlayersWay = false

If True, the NPC will attempt to keep out of the Player's way