KROYSDOCS
HomeWhat's newv0.1.0
SCRIPTING API / Characters and gameplay / CharacterController

CharacterController

Script access to an entity's Character Controller: the capsule that walks, jumps and climbs slopes in fixed steps, driven by player input or by script motion (SetScriptMotion, SetScriptMove).

Kindclass
NamespaceKroys.EngineScripting
Members81
SourceGenerated/NativeComponents.g.cs, NativeComponents.cs
EXAMPLE

In a script

Component access: every member takes the entity first, for example CharacterController.Has(Entity). The values are the ones the Inspector shows for this component.

Gameplay.cs
public sealed class PatrolGuard : EntityScript
{
    public Vector3 PointA = new(0.0f, 0.0f, 0.0f);
    public Vector3 PointB = new(10.0f, 0.0f, 0.0f);
    private bool toB = true;

    protected override void OnStart()
    {
        // Script motion: the character ignores player input and walks where the script says.
        CharacterController.SetScriptMotion(Entity, true);
        CharacterController.SetWalkSpeed(Entity, 2.5f);
    }

    protected override void OnFixedUpdate(float fixedDeltaTime)
    {
        Vector3 target = toB ? PointB : PointA;
        Vector3 toTarget = target - Transform.WorldPosition;
        toTarget.Y = 0.0f;
        if (toTarget.Length() < 0.3f)
        {
            toB = !toB;
            return;
        }
        CharacterController.SetScriptMove(Entity, Vector3.Normalize(toTarget));

        // Achieved velocity is what the move really did after collisions: zero against a wall.
        if (CharacterController.IsGrounded(Entity) && CharacterController.GetAchievedVelocity(Entity).Length() < 0.05f)
            CharacterController.SetJumpPending(Entity, true);   // stuck: try a hop
    }
}
REFERENCE

Members

Methods
#public static bool Has(Entity e)
Whether the entity has a Character Controller component.
methodstatic
#public static bool IsEnabled(Entity e)
Reads the Character Controller component's Enabled value of the entity.
methodstatic
#public static void SetEnabled(Entity e, bool value)
Sets the Character Controller component's Enabled value on the entity.
methodstatic
#public static bool IsGrounded(Entity e)
Standing on ground; brief contact losses (seams, curbs) shorter than the grounded grace keep it true.
methodstatic
#public static bool HasGroundContact(Entity e)
The physics character's raw ground contact of the last fixed step, without the grounded grace.
methodstatic
#public static float GetGroundedGrace(Entity e)
Reads the Character Controller component's Grounded Grace value of the entity.
methodstatic
#public static void SetGroundedGrace(Entity e, float value)
Seconds Grounded stays true after ground contact is lost (0 reports the raw contact).
methodstatic
#public static Vector3 GetAchievedVelocity(Entity e)
World velocity the last fixed-step move achieved after collisions, slides, steps and moving ground (zero against a wall); GetVelocity is the requested motion.
methodstatic
#public static bool IsRotateWithMouseEnabled(Entity e)
Reads the Character Controller component's Rotate With Mouse Enabled value of the entity.
methodstatic
#public static void SetRotateWithMouse(Entity e, bool value)
Sets the Character Controller component's Rotate With Mouse value on the entity.
methodstatic
#public static bool RequiresRightMouseLook(Entity e)
Reads the Character Controller component's Right Mouse Look value of the entity.
methodstatic
#public static void SetRequireRightMouseLook(Entity e, bool value)
Sets the Character Controller component's Require Right Mouse Look value on the entity.
methodstatic
#public static bool IsScriptMotion(Entity e)
A script-driven character ignores player input, for AI and cutscenes.
methodstatic
#public static void SetScriptMotion(Entity e, bool value)
Sets the Character Controller component's Script Motion value on the entity.
methodstatic
#public static void SetScriptMove(Entity e, Vector3 direction)
World-space walking direction while script motion is on; zero stands still.
methodstatic
#public static bool IsJumpPending(Entity e)
Reads the Character Controller component's Jump Pending value of the entity.
methodstatic
#public static void SetJumpPending(Entity e, bool value)
Sets the Character Controller component's Jump Pending value on the entity.
methodstatic
#public static float GetHeight(Entity e)
Reads the Character Controller component's Height value of the entity.
methodstatic
#public static void SetHeight(Entity e, float value)
Sets the Character Controller component's Height value on the entity.
methodstatic
#public static float GetRadius(Entity e)
Reads the Character Controller component's Radius value of the entity.
methodstatic
#public static void SetRadius(Entity e, float value)
Sets the Character Controller component's Radius value on the entity.
methodstatic
#public static float GetWalkSpeed(Entity e)
Reads the Character Controller component's Walk Speed value of the entity.
methodstatic
#public static void SetWalkSpeed(Entity e, float value)
Sets the Character Controller component's Walk Speed value on the entity.
methodstatic
#public static float GetRunMultiplier(Entity e)
Reads the Character Controller component's Run Multiplier value of the entity.
methodstatic
#public static void SetRunMultiplier(Entity e, float value)
Sets the Character Controller component's Run Multiplier value on the entity.
methodstatic
#public static float GetJumpSpeed(Entity e)
Reads the Character Controller component's Jump Speed value of the entity.
methodstatic
#public static void SetJumpSpeed(Entity e, float value)
Sets the Character Controller component's Jump Speed value on the entity.
methodstatic
#public static float GetGravity(Entity e)
Reads the Character Controller component's Gravity value of the entity.
methodstatic
#public static void SetGravity(Entity e, float value)
Sets the Character Controller component's Gravity value on the entity.
methodstatic
#public static float GetMaxSlopeAngle(Entity e)
Reads the Character Controller component's Max Slope Angle value of the entity.
methodstatic
#public static void SetMaxSlopeAngle(Entity e, float value)
Sets the Character Controller component's Max Slope Angle value on the entity.
methodstatic
#public static float GetGroundCheckDistance(Entity e)
Reads the Character Controller component's Ground Check Distance value of the entity.
methodstatic
#public static void SetGroundCheckDistance(Entity e, float value)
Sets the Character Controller component's Ground Check Distance value on the entity.
methodstatic
#public static float GetMouseSensitivity(Entity e)
Reads the Character Controller component's Mouse Sensitivity value of the entity.
methodstatic
#public static void SetMouseSensitivity(Entity e, float value)
Sets the Character Controller component's Mouse Sensitivity value on the entity.
methodstatic
#public static float GetJumpImpulseDelay(Entity e)
Reads the Character Controller component's Jump Impulse Delay value of the entity.
methodstatic
#public static void SetJumpImpulseDelay(Entity e, float value)
Sets the Character Controller component's Jump Impulse Delay value on the entity.
methodstatic
#public static float GetCoyoteTime(Entity e)
Reads the Character Controller component's Coyote Time value of the entity.
methodstatic
#public static void SetCoyoteTime(Entity e, float value)
Sets the Character Controller component's Coyote Time value on the entity.
methodstatic
#public static float GetJumpBuffer(Entity e)
Reads the Character Controller component's Jump Buffer value of the entity.
methodstatic
#public static void SetJumpBuffer(Entity e, float value)
Sets the Character Controller component's Jump Buffer value on the entity.
methodstatic
#public static float GetAirControl(Entity e)
Reads the Character Controller component's Air Control value of the entity.
methodstatic
#public static void SetAirControl(Entity e, float value)
Sets the Character Controller component's Air Control value on the entity.
methodstatic
#public static float GetJumpDelayTimer(Entity e)
Reads the Character Controller component's Jump Delay Timer value of the entity.
methodstatic
#public static float GetJumpBufferTimer(Entity e)
Reads the Character Controller component's Jump Buffer Timer value of the entity.
methodstatic
#public static float GetGroundedGraceTimer(Entity e)
Reads the Character Controller component's Grounded Grace Timer value of the entity.
methodstatic
#public static Vector3 GetVisualLocalPosition(Entity e)
Reads the Character Controller component's Visual Local Position value of the entity.
methodstatic
#public static void SetVisualLocalPosition(Entity e, Vector3 value)
Sets the Character Controller component's Visual Local Position value on the entity.
methodstatic
#public static Vector3 GetVisualLocalRotation(Entity e)
Reads the Character Controller component's Visual Local Rotation value of the entity.
methodstatic
#public static void SetVisualLocalRotation(Entity e, Vector3 value)
Sets the Character Controller component's Visual Local Rotation value on the entity.
methodstatic
#public static Vector3 GetVisualLocalScale(Entity e)
Reads the Character Controller component's Visual Local Scale value of the entity.
methodstatic
#public static void SetVisualLocalScale(Entity e, Vector3 value)
Sets the Character Controller component's Visual Local Scale value on the entity.
methodstatic
#public static Vector3 GetVelocity(Entity e)
Reads the Character Controller component's Velocity value of the entity.
methodstatic
#public static void SetVelocity(Entity e, Vector3 value)
Sets the Character Controller component's Velocity value on the entity.
methodstatic
#public static Entity GetVisualRoot(Entity e)
Reads the Character Controller component's Visual Root value of the entity.
methodstatic
#public static Entity FindPlayer(Entity e)
The first other character no script is driving, which is the player.
methodstatic
#public static void SetVisualRoot(Entity e, Entity visualRoot)
Sets the Character Controller component's Visual Root value on the entity.
methodstatic
#public static bool IsCrouched(Entity e)
Reads the Character Controller component's Crouched value of the entity.
methodstatic
#public static void SetCrouch(Entity e, bool crouch)
Crouches (true) or stands up when there is headroom (false); the player's Crouch action also crouches.
methodstatic
#public static float GetCrouchHeight(Entity e)
Reads the Character Controller component's Crouch Height value of the entity.
methodstatic
#public static void SetCrouchHeight(Entity e, float value)
Sets the Character Controller component's Crouch Height value on the entity.
methodstatic
#public static float GetMaxStepHeight(Entity e)
Reads the Character Controller component's Max Step Height value of the entity.
methodstatic
#public static void SetMaxStepHeight(Entity e, float value)
Sets the Character Controller component's Max Step Height value on the entity.
methodstatic
#public static bool GetPushRigidBodies(Entity e)
Reads the Character Controller component's Push Rigid Bodies value of the entity.
methodstatic
#public static void SetPushRigidBodies(Entity e, bool value)
Sets the Character Controller component's Push Rigid Bodies value on the entity.
methodstatic
#public static float GetPushForce(Entity e)
Reads the Character Controller component's Push Force value of the entity.
methodstatic
#public static void SetPushForce(Entity e, float value)
Sets the Character Controller component's Push Force value on the entity.
methodstatic
#public static float GetPushMaxMass(Entity e)
Reads the Character Controller component's Push Max Mass value of the entity.
methodstatic
#public static void SetPushMaxMass(Entity e, float value)
Sets the Character Controller component's Push Max Mass value on the entity.
methodstatic
#public static float GetPushMinClosingSpeed(Entity e)
Reads the Character Controller component's Push Min Closing Speed value of the entity.
methodstatic
#public static void SetPushMinClosingSpeed(Entity e, float value)
Sets the Character Controller component's Push Min Closing Speed value on the entity.
methodstatic
#public static uint GetPushGameplayLayerMask(Entity e)
Reads the Character Controller component's Push Gameplay Layer Mask value of the entity.
methodstatic
#public static void SetPushGameplayLayerMask(Entity e, uint value)
Sets the Character Controller component's Push Gameplay Layer Mask value on the entity.
methodstatic
#public static bool GetSyncVisualTransform(Entity e)
Reads the Character Controller component's Sync Visual Transform value of the entity.
methodstatic
#public static void SetSyncVisualTransform(Entity e, bool value)
Sets the Character Controller component's Sync Visual Transform value on the entity.
methodstatic
#public static float GetCrouchSpeedMultiplier(Entity e)
Reads the Character Controller component's Crouch Speed Multiplier value of the entity.
methodstatic
#public static void SetCrouchSpeedMultiplier(Entity e, float value)
Sets the Character Controller component's Crouch Speed Multiplier value on the entity.
methodstatic
#public static float GetMass(Entity e)
Reads the Character Controller component's Mass value of the entity.
methodstatic
#public static void SetMass(Entity e, float value)
Sets the Character Controller component's Mass value on the entity.
methodstatic
#public static uint GetCollisionLayer(Entity e)
Reads the Character Controller component's Collision Layer value of the entity.
methodstatic
#public static void SetCollisionLayer(Entity e, uint value)
Sets the Character Controller component's Collision Layer value on the entity.
methodstatic
Signatures
public static bool Has(Entity e)
public static bool IsEnabled(Entity e)
public static void SetEnabled(Entity e, bool value)
public static bool IsGrounded(Entity e)
public static bool HasGroundContact(Entity e)
public static float GetGroundedGrace(Entity e)
public static void SetGroundedGrace(Entity e, float value)
public static Vector3 GetAchievedVelocity(Entity e)
public static bool IsRotateWithMouseEnabled(Entity e)
public static void SetRotateWithMouse(Entity e, bool value)
public static bool RequiresRightMouseLook(Entity e)
public static void SetRequireRightMouseLook(Entity e, bool value)
public static bool IsScriptMotion(Entity e)
public static void SetScriptMotion(Entity e, bool value)
public static void SetScriptMove(Entity e, Vector3 direction)
public static bool IsJumpPending(Entity e)
public static void SetJumpPending(Entity e, bool value)
public static float GetHeight(Entity e)
public static void SetHeight(Entity e, float value)
public static float GetRadius(Entity e)
public static void SetRadius(Entity e, float value)
public static float GetWalkSpeed(Entity e)
public static void SetWalkSpeed(Entity e, float value)
public static float GetRunMultiplier(Entity e)
public static void SetRunMultiplier(Entity e, float value)
public static float GetJumpSpeed(Entity e)
public static void SetJumpSpeed(Entity e, float value)
public static float GetGravity(Entity e)
public static void SetGravity(Entity e, float value)
public static float GetMaxSlopeAngle(Entity e)
public static void SetMaxSlopeAngle(Entity e, float value)
public static float GetGroundCheckDistance(Entity e)
public static void SetGroundCheckDistance(Entity e, float value)
public static float GetMouseSensitivity(Entity e)
public static void SetMouseSensitivity(Entity e, float value)
public static float GetJumpImpulseDelay(Entity e)
public static void SetJumpImpulseDelay(Entity e, float value)
public static float GetCoyoteTime(Entity e)
public static void SetCoyoteTime(Entity e, float value)
public static float GetJumpBuffer(Entity e)
public static void SetJumpBuffer(Entity e, float value)
public static float GetAirControl(Entity e)
public static void SetAirControl(Entity e, float value)
public static float GetJumpDelayTimer(Entity e)
public static float GetJumpBufferTimer(Entity e)
public static float GetGroundedGraceTimer(Entity e)
public static Vector3 GetVisualLocalPosition(Entity e)
public static void SetVisualLocalPosition(Entity e, Vector3 value)
public static Vector3 GetVisualLocalRotation(Entity e)
public static void SetVisualLocalRotation(Entity e, Vector3 value)
public static Vector3 GetVisualLocalScale(Entity e)
public static void SetVisualLocalScale(Entity e, Vector3 value)
public static Vector3 GetVelocity(Entity e)
public static void SetVelocity(Entity e, Vector3 value)
public static Entity GetVisualRoot(Entity e)
public static Entity FindPlayer(Entity e)
public static void SetVisualRoot(Entity e, Entity visualRoot)
public static bool IsCrouched(Entity e)
public static void SetCrouch(Entity e, bool crouch)
public static float GetCrouchHeight(Entity e)
public static void SetCrouchHeight(Entity e, float value)
public static float GetMaxStepHeight(Entity e)
public static void SetMaxStepHeight(Entity e, float value)
public static bool GetPushRigidBodies(Entity e)
public static void SetPushRigidBodies(Entity e, bool value)
public static float GetPushForce(Entity e)
public static void SetPushForce(Entity e, float value)
public static float GetPushMaxMass(Entity e)
public static void SetPushMaxMass(Entity e, float value)
public static float GetPushMinClosingSpeed(Entity e)
public static void SetPushMinClosingSpeed(Entity e, float value)
public static uint GetPushGameplayLayerMask(Entity e)
public static void SetPushGameplayLayerMask(Entity e, uint value)
public static bool GetSyncVisualTransform(Entity e)
public static void SetSyncVisualTransform(Entity e, bool value)
public static float GetCrouchSpeedMultiplier(Entity e)
public static void SetCrouchSpeedMultiplier(Entity e, float value)
public static float GetMass(Entity e)
public static void SetMass(Entity e, float value)
public static uint GetCollisionLayer(Entity e)
public static void SetCollisionLayer(Entity e, uint value)

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.