Class KCCUtils
Utility class for static functions involving kinematic character controller.
Namespace: nickmaltbie.OpenKCC.Utils
Assembly: cs.temp.dll.dll
Syntax
public static class KCCUtils
Fields
BufferAngleShove
Small buffer angle when moving into objects.
Declaration
public const float BufferAngleShove = 120F
Field Value
Type | Description |
---|---|
Single |
Epsilon
Epsilon value for spacing out the KCC very small distances.
Declaration
public const float Epsilon = 0.001F
Field Value
Type | Description |
---|---|
Single |
MaxAngleShoveDegrees
Maximum angle between two colliding objects.
Declaration
public const float MaxAngleShoveDegrees = 60F
Field Value
Type | Description |
---|---|
Single |
Methods
AttemptSnapUp(IRaycastHit, ref Vector3, ref Vector3, Quaternion, IKCCConfig)
Attempt to snap up at current height or maximum height of the player's snap up height.
Declaration
public static bool AttemptSnapUp(IRaycastHit hit, ref Vector3 momentum, ref Vector3 position, Quaternion rotation, IKCCConfig config)
Parameters
Type | Name | Description |
---|---|---|
IRaycastHit | hit | Hit event where player collided with the step. |
Vector3 | momentum | Player's remaining movement, will be reduced by the amount the player moves up the current step. |
Vector3 | position | Player's current position, modify if the player moves while walking up the step. |
Quaternion | rotation | Player's current rotation. |
IKCCConfig | config |
Returns
Type | Description |
---|---|
Boolean | True if the player snapped up, false otherwise. |
AttemptSnapUp(Single, ref Vector3, ref Vector3, Quaternion, IKCCConfig)
Attempt to snap the player up some distance. This will check if there is available space on the ledge above the point that the player collided with. If there is space, the player will be teleported up some distance. If there is not enough space on the ledge above, then this will move the player back to where they were before the attempt was made.
Declaration
public static bool AttemptSnapUp(float distanceToSnap, ref Vector3 momentum, ref Vector3 position, Quaternion rotation, IKCCConfig config)
Parameters
Type | Name | Description |
---|---|---|
Single | distanceToSnap | Distance that the player is teleported up. |
Vector3 | momentum | The remaining momentum of the player. |
Vector3 | position | Position of the player. |
Quaternion | rotation | Rotation of the player. |
IKCCConfig | config | Config for controlling player movement. |
Returns
Type | Description |
---|---|
Boolean | True if the player had space on the ledge and was able to move, false if there was not enough room the player is moved back to their original position |
CheckPerpendicularBounce(IRaycastHit, Vector3, IKCCConfig)
Check if the character bounced into a surface perpendicular to itself.
Declaration
public static bool CheckPerpendicularBounce(IRaycastHit hit, Vector3 momentum, IKCCConfig config)
Parameters
Type | Name | Description |
---|---|---|
IRaycastHit | hit | Surface the character bounces into. |
Vector3 | momentum | |
IKCCConfig | config | Configuration for collider cast calls. |
Returns
Type | Description |
---|---|
Boolean | True if the step is perpendicular to up, false otherwise. |
GetBouncedMomentumSafe(Vector3, Vector3, Vector3)
Get player's projected movement along a surface.
Declaration
public static Vector3 GetBouncedMomentumSafe(Vector3 momentum, Vector3 planeNormal, Vector3 up)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | momentum | Remaining player momentum. |
Vector3 | planeNormal | Plane normal that the player is bouncing off of. |
Vector3 | up | Upwards direction relative to player. |
Returns
Type | Description |
---|---|
Vector3 | Remaining momentum of the player. |
GetBounces(Vector3, Vector3, Quaternion, IKCCConfig)
Get the bounces for a KCC Utils movement action with a set default behaviour.
Declaration
public static IEnumerable<KCCBounce> GetBounces(Vector3 position, Vector3 movement, Quaternion rotation, IKCCConfig config)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position to start player movement from. |
Vector3 | movement | Movement to move the player. |
Quaternion | rotation | Rotation of the player during movement. |
IKCCConfig | config | Configuration settings for player movement. |
Returns
Type | Description |
---|---|
IEnumerable<KCCBounce> | Bounces that the player makes when hitting objects as part of it's movement. |
GetSnapDelta(Vector3, Quaternion, Vector3, Single, IColliderCast, Int32, Single)
Snap the player down onto the ground
Declaration
public static Vector3 GetSnapDelta(Vector3 position, Quaternion rotation, Vector3 dir, float dist, IColliderCast colliderCast, int layerMask = -1, float skinWidth = 0F)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the kcc |
Quaternion | rotation | Rotation of the kcc. |
Vector3 | dir | Direction to snap the kcc down. |
Single | dist | Maximum distance the kcc can snap. |
IColliderCast | colliderCast | Collider cast component associated with the KCC. |
Int32 | layerMask | |
Single | skinWidth |
Returns
Type | Description |
---|---|
Vector3 |
SingleKCCBounce(Vector3, Vector3, Vector3, Quaternion, IKCCConfig)
Compute a single KCC Bounce from a given position.
Declaration
public static KCCBounce SingleKCCBounce(Vector3 position, Vector3 remainingMomentum, Vector3 movement, Quaternion rotation, IKCCConfig config)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Starting position for bounce. |
Vector3 | remainingMomentum | Remaining momentum of the bounce. |
Vector3 | movement | Initial player input movement. |
Quaternion | rotation | Rotation of the player. |
IKCCConfig | config | Configuration of movement. |
Returns
Type | Description |
---|---|
KCCBounce | Returns KCC Bounce information for current movement. |
SnapPlayerDown(Vector3, Quaternion, Vector3, Single, IColliderCast, IKCCConfig)
Snap the player down onto the ground
Declaration
public static Vector3 SnapPlayerDown(Vector3 position, Quaternion rotation, Vector3 dir, float dist, IColliderCast colliderCast, IKCCConfig kccConfig)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the kcc |
Quaternion | rotation | Rotation of the kcc. |
Vector3 | dir | Direction to snap the kcc down. |
Single | dist | Maximum distance the kcc can snap. |
IColliderCast | colliderCast | Collider cast component associated with the KCC. |
IKCCConfig | kccConfig | Configuration for character controller. |
Returns
Type | Description |
---|---|
Vector3 | Final position of player after snapping. |