Class KCCMovementEngine
Movement engine for the kcc state machine to abstract calls to the KCC Utils for a basic character controller.
Implements
Namespace: nickmaltbie.OpenKCC.Character
Assembly: cs.temp.dll.dll
Syntax
public class KCCMovementEngine : MonoBehaviour, IKCCConfig
Fields
_colliderCast
Collider cast for player shape.
Declaration
public IColliderCast _colliderCast
Field Value
Type | Description |
---|---|
IColliderCast |
CurrentSerializationVersion
Serialization version for the KCCMovementEngine.
Declaration
public const string CurrentSerializationVersion = "v1.0.0"
Field Value
Type | Description |
---|---|
String |
DefaultAnglePower
Default angle power for bouncing and sliding off surfaces.
Declaration
public const float DefaultAnglePower = 2F
Field Value
Type | Description |
---|---|
Single |
DefaultGroundCheckDistance
Default value for distance to check for ground below player.
Declaration
public const float DefaultGroundCheckDistance = 0.25F
Field Value
Type | Description |
---|---|
Single |
DefaultGroundedDistance
Default value for distance from ground player is considered grounded.
Declaration
public const float DefaultGroundedDistance = 0.05F
Field Value
Type | Description |
---|---|
Single |
DefaultMaxBounces
Default maximum number of bounces for computing player movement.
Declaration
public const int DefaultMaxBounces = 5
Field Value
Type | Description |
---|---|
Int32 |
DefaultMaxLaunchVelocity
Max launch speed of player form moving ground.
Declaration
public const float DefaultMaxLaunchVelocity = 2F
Field Value
Type | Description |
---|---|
Single |
DefaultMaxPushSpeed
Default max push speed when moving the player.
Declaration
public const float DefaultMaxPushSpeed = 100F
Field Value
Type | Description |
---|---|
Single |
DefaultStepUpDepth
Default expected depth of a step for walking up staircases.
Declaration
public const float DefaultStepUpDepth = 0.1F
Field Value
Type | Description |
---|---|
Single |
layerMask
Layermask for computing player collisions.
Declaration
public LayerMask layerMask
Field Value
Type | Description |
---|---|
LayerMask |
maxWalkAngle
Max angle the player can walk up before slipping.
Declaration
public float maxWalkAngle
Field Value
Type | Description |
---|---|
Single |
previousPosition
Previous position of the player for calculating moving ground position.
Declaration
protected Vector3 previousPosition
Field Value
Type | Description |
---|---|
Vector3 |
skinWidth
Skin width for player collisions.
Declaration
public float skinWidth
Field Value
Type | Description |
---|---|
Single |
SnapDownModifier
Modifier of step height for snapping the player down.
Declaration
public const float SnapDownModifier = 2F
Field Value
Type | Description |
---|---|
Single |
stepHeight
Height of a step that the player can climb up.
Declaration
public float stepHeight
Field Value
Type | Description |
---|---|
Single |
unityService
Unity service for managing calls to static variables in a testable manner.
Declaration
protected IUnityService unityService
Field Value
Type | Description |
---|---|
IUnityService |
worldVelocity
Approximated world velocity of the player.
Declaration
public SmoothedVector worldVelocity
Field Value
Type | Description |
---|---|
SmoothedVector |
Properties
AnglePower
Angle power for decaying momentum when bouncing off a surface.
Declaration
public virtual float AnglePower { get; }
Property Value
Type | Description |
---|---|
Single |
CanSnapUp
Can the player snap up steps during this movement.
Declaration
public bool CanSnapUp { get; }
Property Value
Type | Description |
---|---|
Boolean |
ColliderCast
Collider cast for player movement.
Declaration
public virtual IColliderCast ColliderCast { get; }
Property Value
Type | Description |
---|---|
IColliderCast |
GroundCheckDistance
Distance to check player distance to ground.
Declaration
public virtual float GroundCheckDistance { get; }
Property Value
Type | Description |
---|---|
Single |
GroundedDistance
Distance to ground at which player is considered grounded.
Declaration
public virtual float GroundedDistance { get; }
Property Value
Type | Description |
---|---|
Single |
GroundedState
Current grounded state of the character.
Declaration
public KCCGroundedState GroundedState { get; protected set; }
Property Value
Type | Description |
---|---|
KCCGroundedState |
LayerMask
Get the layer mask for computing player collisions.
Declaration
public virtual LayerMask LayerMask { get; }
Property Value
Type | Description |
---|---|
LayerMask |
MaxBounces
Maximum bounces when moving the player.
Declaration
public virtual int MaxBounces { get; }
Property Value
Type | Description |
---|---|
Int32 |
MaxDefaultLaunchVelocity
Max default launch velocity for the player from unlabeled surfaces.
Declaration
public virtual float MaxDefaultLaunchVelocity { get; }
Property Value
Type | Description |
---|---|
Single |
MaxPushSpeed
Max push speed of the player in units per second when pushing out of overlapping objects.
Declaration
public float MaxPushSpeed { get; }
Property Value
Type | Description |
---|---|
Single |
MaxSnapDownSpeed
Maximum speed at which the player can snap down surfaces.
Declaration
public virtual float MaxSnapDownSpeed { get; }
Property Value
Type | Description |
---|---|
Single |
MaxWalkAngle
Maximum angle at which the player can walk (in degrees).
Declaration
public virtual float MaxWalkAngle { get; }
Property Value
Type | Description |
---|---|
Single |
RelativeParentConfig
Relative parent configuration for following the ground.
Declaration
public RelativeParentConfig RelativeParentConfig { get; protected set; }
Property Value
Type | Description |
---|---|
RelativeParentConfig |
SkinWidth
The character's collision skin width.
This is dependant on the scale of the world, but should be a small, positive non zero value.
Reference: CharacterController.skinWidth, Unity Documentation - https://docs.unity3d.com/ScriptReference/CharacterController-skinWidth.html
Reference: Character Controllers: Character Volume, Nvidia PhysX SDK - https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/CharacterControllers.html#character-volume
Declaration
public virtual float SkinWidth { get; }
Property Value
Type | Description |
---|---|
Single |
SnapDown
Snap down distance for player snapping down.
Declaration
public virtual float SnapDown { get; }
Property Value
Type | Description |
---|---|
Single |
StepUpDepth
Minimum depth required for a stair when moving onto a step.
Declaration
public virtual float StepUpDepth { get; }
Property Value
Type | Description |
---|---|
Single |
Up
Upwards direction for the KCC Movement engine.
Declaration
public virtual Vector3 Up { get; }
Property Value
Type | Description |
---|---|
Vector3 |
VerticalSnapUp
Vertical snap up distance the player can snap up.
Declaration
public virtual float VerticalSnapUp { get; }
Property Value
Type | Description |
---|---|
Single |
Methods
Awake()
Setup and configure the movement engine.
Declaration
public void Awake()
CheckGrounded(Boolean, Boolean)
Update the current grounded state of this kinematic character controller.
Declaration
public virtual KCCGroundedState CheckGrounded(bool snappedUp, bool snappedDown)
Parameters
Type | Name | Description |
---|---|---|
Boolean | snappedUp | |
Boolean | snappedDown |
Returns
Type | Description |
---|---|
KCCGroundedState |
GetGroundVelocity()
Gets the velocity of the ground the player is standing on where the player is currently
Declaration
public virtual Vector3 GetGroundVelocity()
Returns
Type | Description |
---|---|
Vector3 | The velocity of the ground at the point the player is standing on |
GetMovement(Vector3)
Get the bounces for a KCC Utils movement action with a set default behaviour.
Declaration
public virtual IEnumerable<KCCBounce> GetMovement(Vector3 movement)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | movement | Movement to move the player. |
Returns
Type | Description |
---|---|
IEnumerable<KCCBounce> | Bounces that the player makes when hitting objects as part of it's movement. |
GetProjectedMovement(Vector3)
Get the movement of the player projected onto the plane they are standing on if they are not falling.
Declaration
public virtual Vector3 GetProjectedMovement(Vector3 movement)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | movement | How the player is attempting to move. |
Returns
Type | Description |
---|---|
Vector3 | Projected movement onto the plane the player is standing on. |
MovePlayer(Vector3[])
Applies player movement based current configuration. Includes pushing out overlapping objects, updating grounded state, jumping, moving the player, and updating the grounded state.
Declaration
public virtual KCCBounce[] MovePlayer(params Vector3[] moves)
Parameters
Type | Name | Description |
---|---|---|
Vector3[] | moves | Desired player movement in world space. |
Returns
Type | Description |
---|---|
KCCBounce[] |
MovingUp(Vector3)
Is the a movement vector is moving in the direction upwards relative to player direction.
Declaration
public bool MovingUp(Vector3 move)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | move |
Returns
Type | Description |
---|---|
Boolean |
OnAfterDeserialize()
Movement engine for the kcc state machine to abstract calls to the KCC Utils for a basic character controller.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Movement engine for the kcc state machine to abstract calls to the KCC Utils for a basic character controller.
Declaration
public void OnBeforeSerialize()
ShouldSnapDown(Boolean, IEnumerable<Vector3>)
Should the player snap down after a movement.
Declaration
protected virtual bool ShouldSnapDown(bool snappedUp, IEnumerable<Vector3> moves)
Parameters
Type | Name | Description |
---|---|---|
Boolean | snappedUp | Did the player snap up during their movement. |
IEnumerable<Vector3> | moves | Movement bounces of the player. |
Returns
Type | Description |
---|---|
Boolean | True if the player should snap down, false otherwise. |
SnapPlayerDown()
Snap the player down onto the ground
Declaration
protected virtual void SnapPlayerDown()
TeleportPlayer(Vector3)
Teleport player to a given position.
Declaration
public virtual void TeleportPlayer(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position to teleport player to. |
Update()
Have the player to visually move with the ground.
Declaration
public void Update()