Character Controller Pro  1.3.8
A 2D/3D character controller asset for the Unity Engine.
Lightbug.CharacterControllerPro.Core.CharacterActor Class Reference

This class represents a character actor. It contains all the character information, collision flags, collision events, and so on. It also responsible for the execution order of everything related to the character, such as movement, rotation, teleportation, rigidbodies interactions, body size, etc. Since the character can be 2D or 3D, this abstract class must be implemented in the two formats, one for 2D and one for 3D. More...

Inheritance diagram for Lightbug.CharacterControllerPro.Core.CharacterActor:
Lightbug.CharacterControllerPro.Core.PhysicsActor

Public Types

enum  CharacterVelocityMode { UseInputVelocity, UsePreSimulationVelocity, UsePostSimulationVelocity }
 
enum  SizeReferenceType { Top, Center, Bottom }
 
- Public Types inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
enum  RootMotionVelocityType { RootMotionVelocityType.SetVelocity, RootMotionVelocityType.SetPlanarVelocity, RootMotionVelocityType.SetVerticalVelocity }
 Defines how the root velocity data is going to be applied to the actor. More...
 
enum  RootMotionRotationType { RootMotionRotationType.SetRotation, RootMotionRotationType.AddRotation }
 Defines how the root rotation data is going to be applied to the actor. More...
 

Public Member Functions

void OnValidate ()
 
void SetUpRootMotion (bool updateRootPosition=true, bool updateRootRotation=true)
 Sets up root motion for this actor. More...
 
void SetUpRootMotion (bool updateRootPosition=true, RootMotionVelocityType rootMotionVelocityType=RootMotionVelocityType.SetVelocity, bool updateRootRotation=true, RootMotionRotationType rootMotionRotationType=RootMotionRotationType.AddRotation)
 Sets up root motion for this actor. More...
 
Vector3 GetGroundPointVelocity (Vector3 position)
 Returns the point velocity (Rigidbody API) of the ground at a given position. More...
 
override string ToString ()
 Returns a concatenated string containing all the current collision information. More...
 
Vector3 GetCenter (Vector3 position)
 Gets the center of the collision shape. More...
 
Vector3 GetTop (Vector3 position)
 Gets the top most point of the collision shape. More...
 
Vector3 GetBottom (Vector3 position)
 Gets the bottom most point of the collision shape. More...
 
Vector3 GetTopCenter (Vector3 position)
 Gets the center of the top sphere of the collision shape. More...
 
Vector3 GetTopCenter (Vector3 position, Vector2 bodySize)
 Gets the center of the top sphere of the collision shape (considering an arbitrary body size). More...
 
Vector3 GetBottomCenter (Vector3 position, float bottomOffset=0f)
 Gets the center of the bottom sphere of the collision shape. More...
 
Vector3 GetBottomCenter (Vector3 position, Vector2 bodySize)
 Gets the center of the bottom sphere of the collision shape (considering an arbitrary body size). More...
 
Vector3 GetBottomCenterToTopCenter ()
 Gets the a vector that goes from the bottom center to the top center (topCenter - bottomCenter). More...
 
Vector3 GetBottomCenterToTopCenter (Vector2 bodySize)
 Gets the a vector that goes from the bottom center to the top center (topCenter - bottomCenter). More...
 
void SetYaw (float angle)
 Rotates the character doing yaw rotation (around its vertical axis). More...
 
void Teleport (Transform reference)
 Sets the teleportation position and rotation using an external Transform reference. The character will move/rotate internally using its own internal logic. More...
 
void Teleport (Vector3 position, Quaternion rotation)
 Sets the teleportation position and rotation. The character will move/rotate internally using its own internal logic. More...
 
void Teleport (Vector3 position)
 Sets the teleportation position. The character will move/rotate internally using its own internal logic. More...
 
void Move (Vector3 position)
 Sets the rigidbody velocity based on a target position. The same can be achieved by setting the velocity value manually. More...
 
bool SetBodySize (Vector2 size)
 Checks if the new character size fits in place. If this check is valid then the real size of the character is changed. More...
 
void SweepAndTeleport (Vector3 destination)
 Sweeps the body from its current position (CharacterActor.Position) towards the desired destination using the "collide and slide" algorithm. At the end, the character will be moved to a valid position. Triggers and one way platforms will be ignored. More...
 
void SweepAndTeleport (Vector3 destination, in HitInfoFilter filter)
 Sweeps the body from its current position (CharacterActor.Position) towards the desired destination using the "collide and slide" algorithm. At the end, the character will be moved to a valid position. More...
 
void ForceGrounded ()
 Forces the character to be grounded (isGrounded = true) if possible. The detection distance includes the step down distance. More...
 
Vector3 GetGroundSlopeNormal (in CollisionInfo collisionInfo)
 
void ForceNotGrounded (int ignoreGroundContactFrames=3)
 Forces the character to abandon the grounded state (isGrounded = false). More...
 
bool CheckOneWayPlatformLayerMask (CollisionInfo collisionInfo)
 
bool CheckOneWayPlatformCollision (Vector3 contactPoint, Vector3 characterPosition)
 
- Public Member Functions inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
void SyncBody ()
 
void InitializeAnimation (Animator animator)
 Configures all the animation-related components based on a given Animator component. The Animator provides root motion data along More...
 
void ResetIKWeights ()
 
void ResetInterpolationPosition ()
 
void ResetInterpolationRotation ()
 

Public Attributes

LayerMask oneWayPlatformsLayerMask = 0
 
float oneWayPlatformsValidArc = 175f
 
bool useGroundTrigger = false
 
bool alwaysNotGrounded = false
 
bool forceGroundedAtStart = true
 
LayerMask stableLayerMask = -1
 
float slopeLimit = 55f
 
bool useStableEdgeWhenLanding = true
 
float stepUpDistance = 0.5f
 
float stepDownDistance = 0.5f
 
bool edgeCompensation = false
 
bool detectGroundWhileAscending = false
 
bool preventUnstableClimbing = true
 
bool preventBadSteps = true
 
bool supportDynamicGround = true
 
LayerMask dynamicGroundLayerMask = -1
 
bool rotateForwardDirection = true
 
float maxGroundVelocityChange = 30f
 
float inheritedGroundPlanarVelocityThreshold = 2f
 
float inheritedGroundPlanarVelocityMultiplier = 1f
 
float inheritedGroundVerticalVelocityThreshold = 2f
 
float inheritedGroundVerticalVelocityMultiplier = 1f
 
bool slideOnWalls = true
 
CharacterVelocityMode stablePostSimulationVelocity = CharacterVelocityMode.UsePostSimulationVelocity
 
CharacterVelocityMode unstablePostSimulationVelocity = CharacterVelocityMode.UsePostSimulationVelocity
 
SizeReferenceType sizeReferenceType = SizeReferenceType.Bottom
 
float sizeLerpSpeed = 8f
 
bool constraintRotation = true
 
Transform upDirectionReference = null
 
VerticalAlignmentSettings.VerticalReferenceMode upDirectionReferenceMode = VerticalAlignmentSettings.VerticalReferenceMode.Away
 
Vector3 constraintUpDirection = Vector3.up
 
bool canPushDynamicRigidbodies = true
 
LayerMask pushableRigidbodyLayerMask = -1
 
bool applyWeightToGround = true
 
float weightGravity = CharacterConstants.DefaultGravity
 
bool Is2D => RigidbodyComponent.Is2D
 Gets the CharacterBody component associated with this character actor. More...
 
override RigidbodyComponent RigidbodyComponent => CharacterBody.RigidbodyComponent
 Gets the RigidbodyComponent component associated with the character. More...
 
ColliderComponent ColliderComponent => CharacterBody.ColliderComponent
 Gets the ColliderComponent component associated with the character. More...
 
LayerMask ObstaclesLayerMask => PhysicsComponent.CollisionLayerMask | oneWayPlatformsLayerMask
 
LayerMask ObstaclesWithoutOWPLayerMask => PhysicsComponent.CollisionLayerMask & ~(oneWayPlatformsLayerMask)
 
bool IsOnEdge => characterCollisionInfo.isOnEdge
 Returns true if the character is standing on an edge. More...
 
float EdgeAngle => characterCollisionInfo.edgeAngle
 Returns the angle between the both sides of the edge. More...
 
bool IsGrounded => characterCollisionInfo.groundObject != null
 Gets the grounded state, true if the ground object is not null, false otherwise. More...
 
float GroundSlopeAngle => characterCollisionInfo.groundSlopeAngle
 Gets the angle between the up vector and the stable normal. More...
 
Vector3 GroundContactPoint => characterCollisionInfo.groundContactPoint
 Gets the contact point obtained directly from the ground test (sphere cast). More...
 
Vector3 GroundContactNormal => characterCollisionInfo.groundContactNormal
 Gets the normal vector obtained directly from the ground test (sphere cast). More...
 
Vector3 GroundStableNormal => IsStable ? characterCollisionInfo.groundStableNormal : Up
 Gets the normal vector used to determine stability. This may or may not be the normal obtained from the ground test. More...
 
GameObject GroundObject => characterCollisionInfo.groundObject
 Gets the GameObject component of the current ground. More...
 
Transform GroundTransform => GroundObject != null ? GroundObject.transform : null
 Gets the Transform component of the current ground. More...
 
Collider2D GroundCollider2D => characterCollisionInfo.groundCollider2D
 Gets the Collider2D component of the current ground. More...
 
Collider GroundCollider3D => characterCollisionInfo.groundCollider3D
 Gets the Collider3D component of the current ground. More...
 
Rigidbody2D GroundRigidbody2D => characterCollisionInfo.groundRigidbody2D
 Gets the Rigidbody2D component of the current ground. More...
 
Rigidbody GroundRigidbody3D => characterCollisionInfo.groundRigidbody3D
 Gets the Rigidbody component of the current ground. More...
 
bool WallCollision => characterCollisionInfo.wallCollision
 Gets the wall collision flag, true if the character hit a wall, false otherwise. More...
 
float WallAngle => characterCollisionInfo.wallAngle
 Gets the angle between the contact normal (wall collision) and the Up direction. More...
 
Contact WallContact => characterCollisionInfo.wallContact
 Gets the current contact (wall collision). More...
 
bool HeadCollision => characterCollisionInfo.headCollision
 Gets the head collision flag, true if the character hits something with its head, false otherwise. More...
 
float HeadAngle => characterCollisionInfo.headAngle
 Gets the angle between the contact normal (head collision) and the Up direction. More...
 
Contact HeadContact => characterCollisionInfo.headContact
 Gets the current contact (head collision). More...
 
bool IsOnUnstableGround => IsGrounded && characterCollisionInfo.groundSlopeAngle > slopeLimit
 Returns true if the character is grounded onto an unstable ground, false otherwise. More...
 
CharacterCollisionInfo CharacterCollisionInfo => characterCollisionInfo
 Gets a structure with all the information regarding character collisions. Most of the character properties (e.g. IsGrounded, IsStable, GroundObject, and so on) can be obtained from this structure. More...
 
Vector2 DefaultBodySize => CharacterBody.BodySize
 Gets the current body size (width and height). More...
 
CharacterCollisions CharacterCollisions => characterCollisions
 
List< ContactWallContacts => wallContacts
 Returns a lits of all the contacts involved with wall collision events. More...
 
List< ContactHeadContacts => headContacts
 Returns a lits of all the contacts involved with head collision events. More...
 
List< ContactGroundContacts => groundContacts
 Returns a lits of all the contacts involved with head collision events. More...
 
Vector3 GroundDeltaVelocity => GroundVelocity - PreviousGroundVelocity
 The ground change in velocity (current velocity - previous velocity). More...
 
Vector3 GroundAcceleration => (GroundVelocity - PreviousGroundVelocity) / Time.fixedDeltaTime
 The ground acceleration (GroundDeltaVelocity / dt). More...
 
bool IsGroundAscending => transform.InverseTransformVectorUnscaled(Vector3.Project(CustomUtilities.Multiply(GroundVelocity, Time.deltaTime), Up)).y > 0
 Returns true if the ground vertical displacement (moving ground) is positive. More...
 
bool IsGroundAOneWayPlatform => CustomUtilities.BelongsToLayerMask(GroundObject.layer, oneWayPlatformsLayerMask)
 Returns true if the current ground layer is considered as a one way platform. More...
 
bool CanEnterGroundedState => !alwaysNotGrounded && forceNotGroundedFrames == 0
 
- Public Attributes inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
bool interpolateActor = true
 
bool useContinuousCollisionDetection = true
 
bool UseRootMotion = false
 
bool UpdateRootPosition = true
 
RootMotionVelocityType rootMotionVelocityType = RootMotionVelocityType.SetVelocity
 
bool UpdateRootRotation = true
 
RootMotionRotationType rootMotionRotationType = RootMotionRotationType.AddRotation
 

Protected Member Functions

override void Awake ()
 
override void Start ()
 
override void OnEnable ()
 
override void OnDisable ()
 
virtual void ApplyWeight (Vector3 contactPoint)
 Applies a force at the ground contact point, in the direction of the weight (mass times gravity). More...
 
override void PreSimulationUpdate (float dt)
 
override void PostSimulationUpdate (float dt)
 
override void UpdateDynamicRootMotionPosition (Vector3 deltaPosition)
 
void StableCollideAndSlide (ref Vector3 position, Vector3 displacement, bool useFullBody)
 
void PostSimulationCollideAndSlide (ref Vector3 position, ref Quaternion rotation, Vector3 displacement, bool useFullBody)
 
void UnstableCollideAndSlide (ref Vector3 position, Vector3 displacement, float dt)
 
- Protected Member Functions inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
virtual void UpdateKinematicRootMotionPosition (Vector3 deltaPosition)
 
virtual void UpdateKinematicRootMotionRotation (Quaternion deltaRotation)
 
virtual void UpdateDynamicRootMotionRotation (Quaternion deltaRotation)
 

Protected Attributes

CharacterCollisionInfo characterCollisionInfo = new CharacterCollisionInfo()
 

Properties

float StepOffset [get]
 
PhysicsComponent PhysicsComponent [get]
 Gets the physics component from the character. More...
 
CharacterBody CharacterBody [get]
 Gets the CharacterBody component associated with this character actor. More...
 
CharacterActorState? CurrentState [get]
 Returns the current character actor state. This enum variable contains the information about the grounded and stable state, all in one. More...
 
CharacterActorState? PreviousState [get]
 Returns the character actor state from the previous frame. More...
 
bool IsStable [get]
 Gets the current stability state of the character. Stability is equal to "grounded + slope angle <= slope limit". More...
 
bool WasGrounded [get]
 Gets the previous grounded state. More...
 
bool WasStable [get]
 Gets the previous stability state. More...
 
RigidbodyComponent GroundRigidbodyComponent [get]
 Gets the RigidbodyComponent component from the ground. More...
 
Vector3? GroundPosition [get]
 Gets the ground rigidbody position. More...
 
Quaternion? GroundRotation [get]
 Gets the ground rigidbody rotation. More...
 
bool? IsGroundARigidbody [get]
 Returns true if the current ground is a Rigidbody (2D or 3D), false otherwise. More...
 
bool? IsGroundAKinematicRigidbody [get]
 Returns true if the current ground is a kinematic Rigidbody (2D or 3D), false otherwise. More...
 
float GroundedTime [get]
 
float NotGroundedTime [get]
 
float StableElapsedTime [get]
 
float UnstableElapsedTime [get]
 
Vector2 BodySize [get]
 Gets the current body size (width and height). More...
 
Vector3 Velocity [get, set]
 Gets/Sets the rigidbody velocity. More...
 
Vector3 PlanarVelocity [get, set]
 Gets/Sets the rigidbody velocity projected onto a plane formed by its up direction. More...
 
Vector3 VerticalVelocity [get, set]
 Gets/Sets the rigidbody velocity projected onto its up direction. More...
 
Vector3 StableVelocity [get, set]
 Gets/Sets the rigidbody velocity projected onto a plane formed by its up direction. More...
 
Vector3 LastGroundedVelocity [get]
 
Vector3 LocalVelocity [get, set]
 Gets/Sets the rigidbody local velocity. More...
 
Vector3 LocalPlanarVelocity [get, set]
 Gets/Sets the rigidbody local planar velocity. More...
 
bool IsFalling [get]
 Returns true if the character local vertical velocity is less than zero. More...
 
bool IsAscending [get]
 Returns true if the character local vertical velocity is greater than zero. More...
 
Vector3 Center [get]
 Gets the center of the collision shape. More...
 
Vector3 Top [get]
 Gets the center of the collision shape. More...
 
Vector3 Bottom [get]
 Gets the center of the collision shape. More...
 
Vector3 TopCenter [get]
 Gets the center of the collision shape. More...
 
Vector3 BottomCenter [get]
 Gets the center of the collision shape. More...
 
Vector3 OffsettedBottomCenter [get]
 Gets the center of the collision shape. More...
 
Vector3 Position [get, set]
 Gets/Sets the current rigidbody position. This action will produce an "interpolation reset", meaning that (visually) the object will move instantly to the target. More...
 
Quaternion Rotation [get, set]
 Gets/Sets the current rigidbody rotation. This action will produce an "interpolation reset", meaning that (visually) the object will rotate instantly to the target. More...
 
Vector3 Up [get, set]
 Gets/Sets the current up direction based on the rigidbody rotation (not necessarily transform.up). More...
 
Vector3? Forward [get, set]
 Gets/Sets the current forward direction based on the rigidbody rotation (not necessarily transform.forward). More...
 
Vector3 Right [get]
 Gets the current up direction based on the rigidbody rotation (not necessarily transform.right). More...
 
List< ContactContacts [get]
 Gets a list with all the current contacts. More...
 
Trigger CurrentTrigger [get]
 Gets the most recent trigger. More...
 
List< TriggerTriggers [get]
 Gets a list with all the triggers. More...
 
bool IsKinematic [get, set]
 
Vector3 InputVelocity [get]
 Gets the character velocity vector (Velocity) assigned prior to the FixedUpdate call. This is also known as the "input" velocity, since it is the value the user has specified. More...
 
Vector3 PreSimulationVelocity [get]
 Gets a velocity vector which is the input velocity modified, based on the character actor internal rules (step up, slope limit, etc). This velocity corresponds to the one used by the physics simulation. More...
 
Vector3 PostSimulationVelocity [get]
 Gets the character velocity as the result of the Physics simulation. More...
 
Vector3 ExternalVelocity [get]
 Gets the difference between the post-simulation velocity (after the physics simulation) and the pre-simulation velocity (just before the physics simulation). This value is useful to detect any external response due to the physics simulation, such as hits coming from other rigidbodies. More...
 
Vector3 GroundVelocity [get]
 Gets the velocity of the ground (rigidbody). More...
 
Vector3 PreviousGroundVelocity [get]
 Gets the previous velocity of the ground (rigidbody). More...
 
Vector3 GroundProbingDisplacement [get]
 The last vertical displacement calculated by the ground probabing algorithm (PostGroundProbingPosition - PreGroundProbingPosition). More...
 
Vector3 PreGroundProbingPosition [get]
 The last rigidbody position prior to the ground probing algorithm. More...
 
Vector3 PostGroundProbingPosition [get]
 The last rigidbody position after the ground probing algorithm. More...
 
GameObject PredictedGround [get]
 Gets the object below the character (only valid if the character is falling). The maximum prediction distance is defined by the constant "GroundPredictionDistance". More...
 
float PredictedGroundDistance [get]
 Gets the distance to the "PredictedGround". More...
 
- Properties inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
abstract RigidbodyComponent RigidbodyComponent [get]
 Gets the RigidbodyComponent component associated with the character. More...
 
Animator Animator [get]
 Gets the Animator component associated with the state controller. More...
 
float InterpolationFactor [get]
 Returns a value between 0 and 1 that represents the interpolation t factor used by the interpolation algorithm. If the current time value (Time.time) is close to the most recent fixed time (Time.fixedTime), then the factor will be close to 0. On the other hand, if the current time is close to the next fixed time value (Time.fixedTime + Time.fixedDeltaTime) then the factor will be close to 1. More...
 

Events

System.Action< ContactOnHeadHit
 This event is called when the character hits its head (not grounded). More...
 
System.Action< ContactOnWallHit
 This event is called everytime the character is blocked by an unallowed geometry, this could be a wall or a steep slope (depending on the "slopeLimit" value). More...
 
System.Action< Vector3, Quaternion > OnTeleport
 This event is called everytime the character teleports. More...
 
System.Action< Vector3 > OnGroundedStateEnter
 This event is called when the character enters the grounded state. More...
 
System.Action OnGroundedStateExit
 This event is called when the character exits the grounded state. More...
 
System.Action OnNewGroundEnter
 This event is called when the character make contact with a new ground (object). More...
 
- Events inherited from Lightbug.CharacterControllerPro.Core.PhysicsActor
System.Action< float > OnPreSimulation
 This event is called prior to the physics simulation. More...
 
System.Action< float > OnPostSimulation
 This event is called after the physics simulation. More...
 
System.Action< Vector3, Quaternion > OnAnimatorMoveEvent
 
System.Action< int > OnAnimatorIKEvent
 

Detailed Description

This class represents a character actor. It contains all the character information, collision flags, collision events, and so on. It also responsible for the execution order of everything related to the character, such as movement, rotation, teleportation, rigidbodies interactions, body size, etc. Since the character can be 2D or 3D, this abstract class must be implemented in the two formats, one for 2D and one for 3D.

Member Function Documentation

◆ ApplyWeight()

virtual void Lightbug.CharacterControllerPro.Core.CharacterActor.ApplyWeight ( Vector3  contactPoint)
inlineprotectedvirtual

Applies a force at the ground contact point, in the direction of the weight (mass times gravity).

◆ ForceGrounded()

void Lightbug.CharacterControllerPro.Core.CharacterActor.ForceGrounded ( )
inline

Forces the character to be grounded (isGrounded = true) if possible. The detection distance includes the step down distance.

◆ ForceNotGrounded()

void Lightbug.CharacterControllerPro.Core.CharacterActor.ForceNotGrounded ( int  ignoreGroundContactFrames = 3)
inline

Forces the character to abandon the grounded state (isGrounded = false).

TIP: This is useful when making the character jump.

Parameters
ignoreGroundContactFramesThe number of FixedUpdate frames to consume in order to prevent the character to re-enter grounded state right after a ForceNotGrounded call.

◆ GetBottom()

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetBottom ( Vector3  position)
inline

Gets the bottom most point of the collision shape.

◆ GetBottomCenter() [1/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetBottomCenter ( Vector3  position,
float  bottomOffset = 0f 
)
inline

Gets the center of the bottom sphere of the collision shape.

◆ GetBottomCenter() [2/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetBottomCenter ( Vector3  position,
Vector2  bodySize 
)
inline

Gets the center of the bottom sphere of the collision shape (considering an arbitrary body size).

◆ GetBottomCenterToTopCenter() [1/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetBottomCenterToTopCenter ( )
inline

Gets the a vector that goes from the bottom center to the top center (topCenter - bottomCenter).

◆ GetBottomCenterToTopCenter() [2/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetBottomCenterToTopCenter ( Vector2  bodySize)
inline

Gets the a vector that goes from the bottom center to the top center (topCenter - bottomCenter).

◆ GetCenter()

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetCenter ( Vector3  position)
inline

Gets the center of the collision shape.

◆ GetGroundPointVelocity()

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetGroundPointVelocity ( Vector3  position)
inline

Returns the point velocity (Rigidbody API) of the ground at a given position.

◆ GetTop()

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetTop ( Vector3  position)
inline

Gets the top most point of the collision shape.

◆ GetTopCenter() [1/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetTopCenter ( Vector3  position)
inline

Gets the center of the top sphere of the collision shape.

◆ GetTopCenter() [2/2]

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GetTopCenter ( Vector3  position,
Vector2  bodySize 
)
inline

Gets the center of the top sphere of the collision shape (considering an arbitrary body size).

◆ Move()

void Lightbug.CharacterControllerPro.Core.CharacterActor.Move ( Vector3  position)
inline

Sets the rigidbody velocity based on a target position. The same can be achieved by setting the velocity value manually.

◆ SetBodySize()

bool Lightbug.CharacterControllerPro.Core.CharacterActor.SetBodySize ( Vector2  size)
inline

Checks if the new character size fits in place. If this check is valid then the real size of the character is changed.

◆ SetUpRootMotion() [1/2]

void Lightbug.CharacterControllerPro.Core.CharacterActor.SetUpRootMotion ( bool  updateRootPosition = true,
bool  updateRootRotation = true 
)
inline

Sets up root motion for this actor.

◆ SetUpRootMotion() [2/2]

void Lightbug.CharacterControllerPro.Core.CharacterActor.SetUpRootMotion ( bool  updateRootPosition = true,
RootMotionVelocityType  rootMotionVelocityType = RootMotionVelocityType.SetVelocity,
bool  updateRootRotation = true,
RootMotionRotationType  rootMotionRotationType = RootMotionRotationType.AddRotation 
)
inline

Sets up root motion for this actor.

◆ SetYaw()

void Lightbug.CharacterControllerPro.Core.CharacterActor.SetYaw ( float  angle)
inline

Rotates the character doing yaw rotation (around its vertical axis).

Parameters
angleThe angle in degrees.

◆ SweepAndTeleport() [1/2]

void Lightbug.CharacterControllerPro.Core.CharacterActor.SweepAndTeleport ( Vector3  destination)
inline

Sweeps the body from its current position (CharacterActor.Position) towards the desired destination using the "collide and slide" algorithm. At the end, the character will be moved to a valid position. Triggers and one way platforms will be ignored.

◆ SweepAndTeleport() [2/2]

void Lightbug.CharacterControllerPro.Core.CharacterActor.SweepAndTeleport ( Vector3  destination,
in HitInfoFilter  filter 
)
inline

Sweeps the body from its current position (CharacterActor.Position) towards the desired destination using the "collide and slide" algorithm. At the end, the character will be moved to a valid position.

◆ Teleport() [1/3]

void Lightbug.CharacterControllerPro.Core.CharacterActor.Teleport ( Transform  reference)
inline

Sets the teleportation position and rotation using an external Transform reference. The character will move/rotate internally using its own internal logic.

◆ Teleport() [2/3]

void Lightbug.CharacterControllerPro.Core.CharacterActor.Teleport ( Vector3  position,
Quaternion  rotation 
)
inline

Sets the teleportation position and rotation. The character will move/rotate internally using its own internal logic.

◆ Teleport() [3/3]

void Lightbug.CharacterControllerPro.Core.CharacterActor.Teleport ( Vector3  position)
inline

Sets the teleportation position. The character will move/rotate internally using its own internal logic.

◆ ToString()

override string Lightbug.CharacterControllerPro.Core.CharacterActor.ToString ( )
inline

Returns a concatenated string containing all the current collision information.

Member Data Documentation

◆ CharacterCollisionInfo

CharacterCollisionInfo Lightbug.CharacterControllerPro.Core.CharacterActor.CharacterCollisionInfo => characterCollisionInfo

Gets a structure with all the information regarding character collisions. Most of the character properties (e.g. IsGrounded, IsStable, GroundObject, and so on) can be obtained from this structure.

◆ ColliderComponent

ColliderComponent Lightbug.CharacterControllerPro.Core.CharacterActor.ColliderComponent => CharacterBody.ColliderComponent

Gets the ColliderComponent component associated with the character.

◆ DefaultBodySize

Vector2 Lightbug.CharacterControllerPro.Core.CharacterActor.DefaultBodySize => CharacterBody.BodySize

Gets the current body size (width and height).

◆ EdgeAngle

float Lightbug.CharacterControllerPro.Core.CharacterActor.EdgeAngle => characterCollisionInfo.edgeAngle

Returns the angle between the both sides of the edge.

◆ GroundAcceleration

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundAcceleration => (GroundVelocity - PreviousGroundVelocity) / Time.fixedDeltaTime

The ground acceleration (GroundDeltaVelocity / dt).

◆ GroundCollider2D

Collider2D Lightbug.CharacterControllerPro.Core.CharacterActor.GroundCollider2D => characterCollisionInfo.groundCollider2D

Gets the Collider2D component of the current ground.

◆ GroundCollider3D

Collider Lightbug.CharacterControllerPro.Core.CharacterActor.GroundCollider3D => characterCollisionInfo.groundCollider3D

Gets the Collider3D component of the current ground.

◆ GroundContactNormal

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundContactNormal => characterCollisionInfo.groundContactNormal

Gets the normal vector obtained directly from the ground test (sphere cast).

◆ GroundContactPoint

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundContactPoint => characterCollisionInfo.groundContactPoint

Gets the contact point obtained directly from the ground test (sphere cast).

◆ GroundContacts

List<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.GroundContacts => groundContacts

Returns a lits of all the contacts involved with head collision events.

◆ GroundDeltaVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundDeltaVelocity => GroundVelocity - PreviousGroundVelocity

The ground change in velocity (current velocity - previous velocity).

◆ GroundObject

GameObject Lightbug.CharacterControllerPro.Core.CharacterActor.GroundObject => characterCollisionInfo.groundObject

Gets the GameObject component of the current ground.

◆ GroundRigidbody2D

Rigidbody2D Lightbug.CharacterControllerPro.Core.CharacterActor.GroundRigidbody2D => characterCollisionInfo.groundRigidbody2D

Gets the Rigidbody2D component of the current ground.

◆ GroundRigidbody3D

Rigidbody Lightbug.CharacterControllerPro.Core.CharacterActor.GroundRigidbody3D => characterCollisionInfo.groundRigidbody3D

Gets the Rigidbody component of the current ground.

◆ GroundSlopeAngle

float Lightbug.CharacterControllerPro.Core.CharacterActor.GroundSlopeAngle => characterCollisionInfo.groundSlopeAngle

Gets the angle between the up vector and the stable normal.

◆ GroundStableNormal

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundStableNormal => IsStable ? characterCollisionInfo.groundStableNormal : Up

Gets the normal vector used to determine stability. This may or may not be the normal obtained from the ground test.

◆ GroundTransform

Transform Lightbug.CharacterControllerPro.Core.CharacterActor.GroundTransform => GroundObject != null ? GroundObject.transform : null

Gets the Transform component of the current ground.

◆ HeadAngle

float Lightbug.CharacterControllerPro.Core.CharacterActor.HeadAngle => characterCollisionInfo.headAngle

Gets the angle between the contact normal (head collision) and the Up direction.

◆ HeadCollision

bool Lightbug.CharacterControllerPro.Core.CharacterActor.HeadCollision => characterCollisionInfo.headCollision

Gets the head collision flag, true if the character hits something with its head, false otherwise.

◆ HeadContact

Contact Lightbug.CharacterControllerPro.Core.CharacterActor.HeadContact => characterCollisionInfo.headContact

Gets the current contact (head collision).

◆ HeadContacts

List<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.HeadContacts => headContacts

Returns a lits of all the contacts involved with head collision events.

◆ Is2D

bool Lightbug.CharacterControllerPro.Core.CharacterActor.Is2D => RigidbodyComponent.Is2D

Gets the CharacterBody component associated with this character actor.

◆ IsGroundAOneWayPlatform

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsGroundAOneWayPlatform => CustomUtilities.BelongsToLayerMask(GroundObject.layer, oneWayPlatformsLayerMask)

Returns true if the current ground layer is considered as a one way platform.

◆ IsGroundAscending

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsGroundAscending => transform.InverseTransformVectorUnscaled(Vector3.Project(CustomUtilities.Multiply(GroundVelocity, Time.deltaTime), Up)).y > 0

Returns true if the ground vertical displacement (moving ground) is positive.

◆ IsGrounded

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsGrounded => characterCollisionInfo.groundObject != null

Gets the grounded state, true if the ground object is not null, false otherwise.

◆ IsOnEdge

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsOnEdge => characterCollisionInfo.isOnEdge

Returns true if the character is standing on an edge.

◆ IsOnUnstableGround

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsOnUnstableGround => IsGrounded && characterCollisionInfo.groundSlopeAngle > slopeLimit

Returns true if the character is grounded onto an unstable ground, false otherwise.

◆ RigidbodyComponent

override RigidbodyComponent Lightbug.CharacterControllerPro.Core.CharacterActor.RigidbodyComponent => CharacterBody.RigidbodyComponent

Gets the RigidbodyComponent component associated with the character.

◆ WallAngle

float Lightbug.CharacterControllerPro.Core.CharacterActor.WallAngle => characterCollisionInfo.wallAngle

Gets the angle between the contact normal (wall collision) and the Up direction.

◆ WallCollision

bool Lightbug.CharacterControllerPro.Core.CharacterActor.WallCollision => characterCollisionInfo.wallCollision

Gets the wall collision flag, true if the character hit a wall, false otherwise.

◆ WallContact

Contact Lightbug.CharacterControllerPro.Core.CharacterActor.WallContact => characterCollisionInfo.wallContact

Gets the current contact (wall collision).

◆ WallContacts

List<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.WallContacts => wallContacts

Returns a lits of all the contacts involved with wall collision events.

Property Documentation

◆ BodySize

Vector2 Lightbug.CharacterControllerPro.Core.CharacterActor.BodySize
get

Gets the current body size (width and height).

◆ Bottom

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Bottom
get

Gets the center of the collision shape.

◆ BottomCenter

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.BottomCenter
get

Gets the center of the collision shape.

◆ Center

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Center
get

Gets the center of the collision shape.

◆ CharacterBody

CharacterBody Lightbug.CharacterControllerPro.Core.CharacterActor.CharacterBody
get

Gets the CharacterBody component associated with this character actor.

◆ Contacts

List<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.Contacts
get

Gets a list with all the current contacts.

◆ CurrentState

CharacterActorState? Lightbug.CharacterControllerPro.Core.CharacterActor.CurrentState
get

Returns the current character actor state. This enum variable contains the information about the grounded and stable state, all in one.

◆ CurrentTrigger

Trigger Lightbug.CharacterControllerPro.Core.CharacterActor.CurrentTrigger
get

Gets the most recent trigger.

◆ ExternalVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.ExternalVelocity
get

Gets the difference between the post-simulation velocity (after the physics simulation) and the pre-simulation velocity (just before the physics simulation). This value is useful to detect any external response due to the physics simulation, such as hits coming from other rigidbodies.

◆ Forward

Vector3? Lightbug.CharacterControllerPro.Core.CharacterActor.Forward
getset

Gets/Sets the current forward direction based on the rigidbody rotation (not necessarily transform.forward).

◆ GroundPosition

Vector3? Lightbug.CharacterControllerPro.Core.CharacterActor.GroundPosition
get

Gets the ground rigidbody position.

◆ GroundProbingDisplacement

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundProbingDisplacement
get

The last vertical displacement calculated by the ground probabing algorithm (PostGroundProbingPosition - PreGroundProbingPosition).

◆ GroundRigidbodyComponent

RigidbodyComponent Lightbug.CharacterControllerPro.Core.CharacterActor.GroundRigidbodyComponent
get

Gets the RigidbodyComponent component from the ground.

◆ GroundRotation

Quaternion? Lightbug.CharacterControllerPro.Core.CharacterActor.GroundRotation
get

Gets the ground rigidbody rotation.

◆ GroundVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.GroundVelocity
get

Gets the velocity of the ground (rigidbody).

◆ InputVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.InputVelocity
get

Gets the character velocity vector (Velocity) assigned prior to the FixedUpdate call. This is also known as the "input" velocity, since it is the value the user has specified.

◆ IsAscending

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsAscending
get

Returns true if the character local vertical velocity is greater than zero.

◆ IsFalling

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsFalling
get

Returns true if the character local vertical velocity is less than zero.

◆ IsGroundAKinematicRigidbody

bool? Lightbug.CharacterControllerPro.Core.CharacterActor.IsGroundAKinematicRigidbody
get

Returns true if the current ground is a kinematic Rigidbody (2D or 3D), false otherwise.

◆ IsGroundARigidbody

bool? Lightbug.CharacterControllerPro.Core.CharacterActor.IsGroundARigidbody
get

Returns true if the current ground is a Rigidbody (2D or 3D), false otherwise.

◆ IsStable

bool Lightbug.CharacterControllerPro.Core.CharacterActor.IsStable
get

Gets the current stability state of the character. Stability is equal to "grounded + slope angle <= slope limit".

◆ LocalPlanarVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.LocalPlanarVelocity
getset

Gets/Sets the rigidbody local planar velocity.

◆ LocalVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.LocalVelocity
getset

Gets/Sets the rigidbody local velocity.

◆ OffsettedBottomCenter

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.OffsettedBottomCenter
get

Gets the center of the collision shape.

◆ PhysicsComponent

PhysicsComponent Lightbug.CharacterControllerPro.Core.CharacterActor.PhysicsComponent
get

Gets the physics component from the character.

◆ PlanarVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PlanarVelocity
getset

Gets/Sets the rigidbody velocity projected onto a plane formed by its up direction.

◆ Position

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Position
getset

Gets/Sets the current rigidbody position. This action will produce an "interpolation reset", meaning that (visually) the object will move instantly to the target.

◆ PostGroundProbingPosition

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PostGroundProbingPosition
get

The last rigidbody position after the ground probing algorithm.

◆ PostSimulationVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PostSimulationVelocity
get

Gets the character velocity as the result of the Physics simulation.

◆ PredictedGround

GameObject Lightbug.CharacterControllerPro.Core.CharacterActor.PredictedGround
get

Gets the object below the character (only valid if the character is falling). The maximum prediction distance is defined by the constant "GroundPredictionDistance".

◆ PredictedGroundDistance

float Lightbug.CharacterControllerPro.Core.CharacterActor.PredictedGroundDistance
get

Gets the distance to the "PredictedGround".

◆ PreGroundProbingPosition

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PreGroundProbingPosition
get

The last rigidbody position prior to the ground probing algorithm.

◆ PreSimulationVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PreSimulationVelocity
get

Gets a velocity vector which is the input velocity modified, based on the character actor internal rules (step up, slope limit, etc). This velocity corresponds to the one used by the physics simulation.

◆ PreviousGroundVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.PreviousGroundVelocity
get

Gets the previous velocity of the ground (rigidbody).

◆ PreviousState

CharacterActorState? Lightbug.CharacterControllerPro.Core.CharacterActor.PreviousState
get

Returns the character actor state from the previous frame.

◆ Right

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Right
get

Gets the current up direction based on the rigidbody rotation (not necessarily transform.right).

◆ Rotation

Quaternion Lightbug.CharacterControllerPro.Core.CharacterActor.Rotation
getset

Gets/Sets the current rigidbody rotation. This action will produce an "interpolation reset", meaning that (visually) the object will rotate instantly to the target.

◆ StableVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.StableVelocity
getset

Gets/Sets the rigidbody velocity projected onto a plane formed by its up direction.

◆ Top

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Top
get

Gets the center of the collision shape.

◆ TopCenter

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.TopCenter
get

Gets the center of the collision shape.

◆ Triggers

List<Trigger> Lightbug.CharacterControllerPro.Core.CharacterActor.Triggers
get

Gets a list with all the triggers.

◆ Up

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Up
getset

Gets/Sets the current up direction based on the rigidbody rotation (not necessarily transform.up).

◆ Velocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.Velocity
getset

Gets/Sets the rigidbody velocity.

◆ VerticalVelocity

Vector3 Lightbug.CharacterControllerPro.Core.CharacterActor.VerticalVelocity
getset

Gets/Sets the rigidbody velocity projected onto its up direction.

◆ WasGrounded

bool Lightbug.CharacterControllerPro.Core.CharacterActor.WasGrounded
get

Gets the previous grounded state.

◆ WasStable

bool Lightbug.CharacterControllerPro.Core.CharacterActor.WasStable
get

Gets the previous stability state.

Event Documentation

◆ OnGroundedStateEnter

System.Action<Vector3> Lightbug.CharacterControllerPro.Core.CharacterActor.OnGroundedStateEnter

This event is called when the character enters the grounded state.

The local linear velocity is passed as an argument.

◆ OnGroundedStateExit

System.Action Lightbug.CharacterControllerPro.Core.CharacterActor.OnGroundedStateExit

This event is called when the character exits the grounded state.

◆ OnHeadHit

System.Action<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.OnHeadHit

This event is called when the character hits its head (not grounded).

The related collision information struct is passed as an argument.

◆ OnNewGroundEnter

System.Action Lightbug.CharacterControllerPro.Core.CharacterActor.OnNewGroundEnter

This event is called when the character make contact with a new ground (object).

◆ OnTeleport

System.Action<Vector3, Quaternion> Lightbug.CharacterControllerPro.Core.CharacterActor.OnTeleport

This event is called everytime the character teleports.

The teleported position and rotation are passed as arguments.

◆ OnWallHit

System.Action<Contact> Lightbug.CharacterControllerPro.Core.CharacterActor.OnWallHit

This event is called everytime the character is blocked by an unallowed geometry, this could be a wall or a steep slope (depending on the "slopeLimit" value).

The related collision information struct is passed as an argument.


The documentation for this class was generated from the following file: