Class KCCController
Kinematic Character Controller wrapper that implements KinematicCharacterController.ICharacterController. Handles movement, jumping, crouching, sprinting, and state transitions.
public class KCCController : MonoBehaviour, ICharacterController
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourKCCController
- Implements
-
ICharacterController
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.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
Fields
AirAccelerationSpeed
Acceleration applied to air movement.
public float AirAccelerationSpeed
Field Value
AllowJumpingWhenSliding
[Header("Jumping")]
public bool AllowJumpingWhenSliding
Field Value
BonusOrientationMethod
Additional orientation method for adjusting the character up vector.
public BonusOrientationMethod BonusOrientationMethod
Field Value
BonusOrientationSharpness
Sharpness for bonus orientation smoothing.
public float BonusOrientationSharpness
Field Value
CameraFollowPoint
Transform that the camera follows and orbits around.
public Transform CameraFollowPoint
Field Value
- Transform
CapsuleBaseOffset
Base offset of the capsule from the character pivot.
public float CapsuleBaseOffset
Field Value
Character
The player character this controller belongs to.
public IPlayerCharacter Character
Field Value
CrouchedCapsuleHeight
Capsule height when crouching.
public float CrouchedCapsuleHeight
Field Value
Drag
Air drag coefficient applied to velocity.
public float Drag
Field Value
FastFallSpeedTemplate
Template for the character attribute that modifies fast fall speed.
public CharacterAttributeTemplate FastFallSpeedTemplate
Field Value
FullCapsuleHeight
Capsule height when standing.
public float FullCapsuleHeight
Field Value
GravityTemplate
Template for the character attribute that modifies gravity.
public CharacterAttributeTemplate GravityTemplate
Field Value
IgnoredColliders
[Header("Misc")]
public List<Collider> IgnoredColliders
Field Value
- List<Collider>
JumpPostGroundingGraceTime
Grace period after leaving ground during which a jump is still allowed.
public float JumpPostGroundingGraceTime
Field Value
JumpPreGroundingGraceTime
Grace period before landing during which a jump request is still accepted.
public float JumpPreGroundingGraceTime
Field Value
JumpScalableForwardSpeed
Forward speed added to velocity when jumping.
public float JumpScalableForwardSpeed
Field Value
JumpSpeedTemplate
Template for the character attribute that modifies jump speed.
public CharacterAttributeTemplate JumpSpeedTemplate
Field Value
MaxAirMoveSpeed
[Header("Air Movement")]
public float MaxAirMoveSpeed
Field Value
MeshRoot
Root transform of the character mesh for visual scaling (e.g., crouch).
public Transform MeshRoot
Field Value
- Transform
Motor
The kinematic character motor driving movement and collision.
public KinematicCharacterMotor Motor
Field Value
- KinematicCharacterMotor
MoveSpeedTemplate
Template for the character attribute that modifies movement speed.
public CharacterAttributeTemplate MoveSpeedTemplate
Field Value
OrientationMethod
Method used to determine character facing direction.
public OrientationMethod OrientationMethod
Field Value
OrientationSharpness
Sharpness for character rotation smoothing.
public float OrientationSharpness
Field Value
SprintSpeedTemplate
Template for the character attribute that modifies sprint speed.
public CharacterAttributeTemplate SprintSpeedTemplate
Field Value
StableMovementSharpness
[Header("Stable Movement")]
public float StableMovementSharpness
Field Value
SwimSpeedTemplate
Template for the character attribute that modifies swim speed.
public CharacterAttributeTemplate SwimSpeedTemplate
Field Value
Properties
CurrentCharacterState
The current state of the character state machine.
public KCCCharacterState CurrentCharacterState { get; }
Property Value
IsJumping
True while the character is in the jumping state.
public bool IsJumping { get; }
Property Value
VirtualCameraPosition
Position of the virtual camera used for input-relative movement calculations.
public Vector3 VirtualCameraPosition { get; }
Property Value
- Vector3
VirtualCameraRotation
Rotation of the virtual camera used for input-relative movement calculations.
public Quaternion VirtualCameraRotation { get; }
Property Value
- Quaternion
Methods
AfterCharacterUpdate(float)
(Called by KinematicCharacterMotor during its update cycle) This is called after the character has finished its movement update
public void AfterCharacterUpdate(float deltaTime)
Parameters
deltaTimefloat
ApplyState(KinematicCharacterMotorState)
Applies a saved motor state to restore the character pose (used during reconcile).
public void ApplyState(KinematicCharacterMotorState state)
Parameters
stateKinematicCharacterMotorStateThe motor state to apply.
BeforeCharacterUpdate(float)
(Called by KinematicCharacterMotor during its update cycle) This is called before the character begins its movement update
public void BeforeCharacterUpdate(float deltaTime)
Parameters
deltaTimefloat
GetState()
Captures the current motor and controller state for reconciliation.
public KinematicCharacterMotorState GetState()
Returns
- KinematicCharacterMotorState
A snapshot of the current kinematic state.
IsColliderValidForCollisions(Collider)
Determines if a collider is valid for collision checks, ignoring those in the IgnoredColliders list.
public bool IsColliderValidForCollisions(Collider coll)
Parameters
collColliderCollider to check.
Returns
- bool
True if valid for collision, false if ignored.
OnDiscreteCollisionDetected(Collider)
Called when a discrete collision is detected. Can be used for collision effects.
public void OnDiscreteCollisionDetected(Collider hitCollider)
Parameters
hitColliderColliderCollider hit.
OnGroundHit(Collider, Vector3, Vector3, ref HitStabilityReport)
Called when the character hits the ground. Can be used for landing effects or stability checks.
public void OnGroundHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
Parameters
hitColliderColliderCollider hit.
hitNormalVector3Normal of the hit surface.
hitPointVector3Point of contact.
hitStabilityReportHitStabilityReportStability report for the hit.
OnLanded()
Called when the character lands on stable ground. Resets jumping state.
protected void OnLanded()
OnLeaveStableGround()
Called when the character leaves stable ground. Can be used for airborne effects.
protected void OnLeaveStableGround()
OnMovementHit(Collider, Vector3, Vector3, ref HitStabilityReport)
Called when the character hits something during movement. Can be used for collision effects.
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
Parameters
hitColliderColliderCollider hit.
hitNormalVector3Normal of the hit surface.
hitPointVector3Point of contact.
hitStabilityReportHitStabilityReportStability report for the hit.
OnStateEnter(KCCCharacterState, KCCCharacterState)
Event when entering a state
public void OnStateEnter(KCCCharacterState state, KCCCharacterState fromState)
Parameters
stateKCCCharacterStatefromStateKCCCharacterState
OnStateExit(KCCCharacterState, KCCCharacterState)
Event when exiting a state
public void OnStateExit(KCCCharacterState state, KCCCharacterState toState)
Parameters
stateKCCCharacterStatetoStateKCCCharacterState
PostGroundingUpdate(float)
Called after grounding update to handle landing and leaving ground events. Triggers OnLanded or OnLeaveStableGround as appropriate.
public void PostGroundingUpdate(float deltaTime)
Parameters
deltaTimefloatFrame time.
ProcessHitStabilityReport(Collider, Vector3, Vector3, Vector3, Quaternion, ref HitStabilityReport)
Processes the hit stability report for advanced collision and grounding logic.
public void ProcessHitStabilityReport(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, Vector3 atCharacterPosition, Quaternion atCharacterRotation, ref HitStabilityReport hitStabilityReport)
Parameters
hitColliderColliderCollider hit.
hitNormalVector3Normal of the hit surface.
hitPointVector3Point of contact.
atCharacterPositionVector3Character position at hit.
atCharacterRotationQuaternionCharacter rotation at hit.
hitStabilityReportHitStabilityReportStability report for the hit.
ResetGroundProbe()
Forces a full-radius ground probe on the next motor update, so a character that has just been placed does not read as airborne for a frame or three.
public void ResetGroundProbe()
Remarks
Call this for a teleport or a fresh spawn — NOT for a reconcile, which restores
LastMovementIterationFoundAnyGround authoritatively and must not have it forced.
SetInputs(ref AICharacterInputs)
This is called every frame by the AI script in order to tell the character what its inputs are
public void SetInputs(ref AICharacterInputs inputs)
Parameters
inputsAICharacterInputs
SetInputs(ref KCCInputReplicateData)
Applies one tick of replicated input. Called from KCCPlayer.OnReplicate, once per
replicated or replayed tick — not per frame, despite the upstream sample's name for it.
public void SetInputs(ref KCCInputReplicateData inputs)
Parameters
inputsKCCInputReplicateData
TransitionToState(KCCCharacterState)
Handles movement state transitions and enter/exit callbacks
public void TransitionToState(KCCCharacterState newState)
Parameters
newStateKCCCharacterState
UpdateRotation(ref Quaternion, float)
(Called by KinematicCharacterMotor during its update cycle) This is where you tell your character what its rotation should be right now. This is the ONLY place where you should set the character's rotation
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
Parameters
currentRotationQuaterniondeltaTimefloat
UpdateVelocity(ref Vector3, float)
(Called by KinematicCharacterMotor during its update cycle) This is where you tell your character what its velocity should be right now. This is the ONLY place where you can set the character's velocity
public void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
Parameters
currentVelocityVector3deltaTimefloat