docs.unity3d.com
    Show / Hide Table of Contents

    Class CharacterControlUtilities

    Contains various utility functions for controlling character velocity and rotation

    Inheritance
    Object
    CharacterControlUtilities
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.CharacterController
    Syntax
    public static class CharacterControlUtilities

    Methods

    AccelerateVelocity(ref float3, float3, Single)

    Accelerates a velocity

    Declaration
    public static void AccelerateVelocity(ref float3 velocity, float3 acceleration, float deltaTime)
    Parameters
    Type Name Description
    float3 velocity

    The modified velocity

    float3 acceleration

    The acceleration strength

    Single deltaTime

    The character update time delta

    ApplyDragToVelocity(ref float3, Single, Single)

    Applies drag to a velocity

    Declaration
    public static void ApplyDragToVelocity(ref float3 velocity, float deltaTime, float drag)
    Parameters
    Type Name Description
    float3 velocity
    Single deltaTime
    Single drag

    ClampAdditiveVelocityToMaxSpeedOnPlane(ref float3, float3, Single, float3, Boolean)

    Add a velocity vector to another velocity, and clamp the resulting total velocity, but only on a given plane (the velocity along the plane's up axis remains unclamped)

    Declaration
    public static void ClampAdditiveVelocityToMaxSpeedOnPlane(ref float3 additiveVelocity, float3 originalVelocity, float maxSpeed, float3 movementPlaneUp, bool forceNoMaxSpeedExcess)
    Parameters
    Type Name Description
    float3 additiveVelocity

    Added velocity

    float3 originalVelocity

    Original velocity

    Single maxSpeed

    Maximum allowed speed on the clamping plane

    float3 movementPlaneUp

    Up direction of the clamping plane

    Boolean forceNoMaxSpeedExcess

    Whether or not to trim character velocity to an absolute maximum (prevents velocity exploits, but can also break preservation of momentum)

    GetLinearVelocityForMovePosition(Single, float3)

    Calculates the velocity required to move by a given position delta over the next time delta

    Declaration
    public static float3 GetLinearVelocityForMovePosition(float deltaTime, float3 positionDelta)
    Parameters
    Type Name Description
    Single deltaTime

    The time delta

    float3 positionDelta

    The position delta

    Returns
    Type Description
    float3

    The required velocity for the move

    GetSlopeAngleTowardsDirection(Boolean, float3, float3, float3)

    Calculates the signed slope angle in a given movement direction. The resulting angle will be positive if the slope goes up, and negative if the slope goes down.

    Declaration
    public static float GetSlopeAngleTowardsDirection(bool useDegrees, float3 moveDirection, float3 slopeNormal, float3 groundingUp)
    Parameters
    Type Name Description
    Boolean useDegrees

    Whether to use degrees or radians for the returned result

    float3 moveDirection

    The direction the character is moving in

    float3 slopeNormal

    The normal of the evaluated slope

    float3 groundingUp

    The character grounding up direction

    Returns
    Type Description
    Single

    The effective signed slope angle

    InterpolateVelocityTowardsTarget(ref float3, float3, Single, Single)

    Interpolates a velocity towards a target velocity, with a given sharpness

    Declaration
    public static void InterpolateVelocityTowardsTarget(ref float3 velocity, float3 targetVelocity, float deltaTime, float interpolationSharpness)
    Parameters
    Type Name Description
    float3 velocity

    The modified velocity

    float3 targetVelocity

    THe target velocity

    Single deltaTime

    The character update time delta

    Single interpolationSharpness

    The sharpness of the velocity change (how quickly it changes)

    SlerpCharacterUpTowardsDirection(ref quaternion, Single, float3, Single)

    Interpolates a rotation to make its up direction point to the designated up direction

    Declaration
    public static void SlerpCharacterUpTowardsDirection(ref quaternion rotation, float deltaTime, float3 direction, float orientationSharpness)
    Parameters
    Type Name Description
    quaternion rotation

    The modified rotation

    Single deltaTime

    The time delta

    float3 direction

    The up direction to face

    Single orientationSharpness

    The sharpness of the rotation (how fast it interpolates)

    SlerpRotationTowardsDirection(ref quaternion, Single, float3, Single)

    Interpolates a rotation to make it face a direction

    Declaration
    public static void SlerpRotationTowardsDirection(ref quaternion rotation, float deltaTime, float3 direction, float orientationSharpness)
    Parameters
    Type Name Description
    quaternion rotation

    The modified rotation

    Single deltaTime

    The time delta

    float3 direction

    The faced direction

    Single orientationSharpness

    The sharpness of the rotation (how fast it interpolates)

    SlerpRotationTowardsDirectionAroundUp(ref quaternion, Single, float3, float3, Single)

    Interpolates a rotation to make it face a direction, but constrains rotation to make it pivot around a designated up axis

    Declaration
    public static void SlerpRotationTowardsDirectionAroundUp(ref quaternion rotation, float deltaTime, float3 direction, float3 upDirection, float orientationSharpness)
    Parameters
    Type Name Description
    quaternion rotation

    The modified rotation

    Single deltaTime

    The time delta

    float3 direction

    The direction to face

    float3 upDirection

    The rotation constraint up axis

    Single orientationSharpness

    The sharpness of the rotation (how fast it interpolates)

    StandardAirMove(ref float3, float3, Single, float3, Single, Boolean)

    Handles updating character velocity for standard accelerated air movement

    Declaration
    public static void StandardAirMove(ref float3 velocity, float3 acceleration, float maxSpeed, float3 movementPlaneUp, float deltaTime, bool forceNoMaxSpeedExcess)
    Parameters
    Type Name Description
    float3 velocity

    Current character velocity

    float3 acceleration

    Acceleration strength

    Single maxSpeed

    Maximum speed that can be reached

    float3 movementPlaneUp

    The up direction of the horizontal reference plane that the character moves on

    Single deltaTime

    The character update time delta

    Boolean forceNoMaxSpeedExcess

    Whether or not to trim character velocity to an absolute maximum (prevents velocity exploits, but can also break preservation of momentum)

    StandardGroundMove_Accelerated(ref float3, float3, Single, Single, float3, float3, Boolean)

    Handles updating character velocity for standard accelerated ground movement

    Declaration
    public static void StandardGroundMove_Accelerated(ref float3 velocity, float3 acceleration, float maxSpeed, float deltaTime, float3 groundingUp, float3 groundedHitNormal, bool forceNoMaxSpeedExcess)
    Parameters
    Type Name Description
    float3 velocity

    Current character velocity

    float3 acceleration

    Acceleration strength

    Single maxSpeed

    Maximum speed that can be reached

    Single deltaTime

    The character update time delta

    float3 groundingUp

    The character's grounding up direction

    float3 groundedHitNormal

    The character ground hit normal

    Boolean forceNoMaxSpeedExcess

    Whether or not to trim character velocity to an absolute maximum (prevents velocity exploits, but can also break preservation of momentum)

    StandardGroundMove_Interpolated(ref float3, float3, Single, Single, float3, float3)

    Handles updating character velocity for standard interpolated ground movement

    Declaration
    public static void StandardGroundMove_Interpolated(ref float3 velocity, float3 targetVelocity, float sharpness, float deltaTime, float3 groundingUp, float3 groundedHitNormal)
    Parameters
    Type Name Description
    float3 velocity

    Current character velocity

    float3 targetVelocity

    Desired character velocity

    Single sharpness

    The sharpness of the velocity change (how quickly it changes)

    Single deltaTime

    The character update time delta

    float3 groundingUp

    The character's grounding up direction

    float3 groundedHitNormal

    The character ground hit normal

    StandardJump(ref KinematicCharacterBody, float3, Boolean, float3)

    Handles standard jumping logic for a character

    Declaration
    public static void StandardJump(ref KinematicCharacterBody characterBody, float3 jumpVelocity, bool cancelVelocityBeforeJump, float3 velocityCancelingUpDirection)
    Parameters
    Type Name Description
    KinematicCharacterBody characterBody

    The character's character body component

    float3 jumpVelocity

    The velocity of the jump

    Boolean cancelVelocityBeforeJump

    Whether or not to cancel-out any velocity in the velocity-canceling up direction before applying the jump velocity

    float3 velocityCancelingUpDirection

    The velocity-canceling up direction

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023