Reading how the player moves
This page uses Vector3, Transform from Unity. The glossary says what each one is.
This is the full list of what the API gives you, one section for each part. Text in brackets at the end of a note is extra detail for experienced modders, and you can skip it on a first read.
These properties give you what the player is doing right now. State() gives several of them together in one PlayerMovementInfo, a snapshot of the speeds and flags at the moment you asked. The snapshot does not update by itself, so ask again for fresh values.
PlayerMovement what the player is doing right now
Read these properties to see what the player is doing now, or call State() to get several of them at once.
public static class PlayerMovement
{
public static bool IsAvailable { get; }
public static bool IsGrounded { get; }
public static bool IsSprinting { get; }
public static bool IsCrouching { get; }
public static Vector3 Velocity { get; }
public static Vector3 Position { get; }
public static PlayerMovementInfo State();
}
| Method | Returns | What it does |
|---|---|---|
State() | PlayerMovementInfo | Several of the properties below in one snapshot. null when no player is loaded. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the speed hooks did not set up. |
IsGrounded | bool | true while the player stands on the ground. |
IsSprinting | bool | true when the player is set to run (see below). |
IsCrouching | bool | true while the player is crouched. |
Velocity | Vector3 | How fast and in which direction the player is moving, in world space. |
Position | Vector3 | Where the player’s body is, in world coordinates. |
PlayerMovementInfo a snapshot of the player's movement
PlayerMovement.State() gives you one of these, with the speeds and states at that moment. It is null when no player is loaded. (The speeds and flags come from the game’s OpenSewerCharacterController.)
public sealed class PlayerMovementInfo
{
public float WalkSpeed { get; }
public float RunSpeed { get; }
public float SwimmingSpeed { get; }
public float CrouchSpeed { get; }
public float BackwardSpeed { get; }
public float StrafeSpeed { get; }
public bool IsCrouching { get; }
public bool IsWalking { get; }
public bool IsGrounded { get; }
public bool ControlsDisabled { get; }
}
| Property | Type | What it means |
|---|---|---|
WalkSpeed | float | How fast the player walks. |
RunSpeed | float | How fast the player runs. |
SwimmingSpeed | float | How fast the player swims. |
CrouchSpeed | float | How fast the player moves while crouching. |
BackwardSpeed | float | The game’s backward speed. It has no effect on movement. |
StrafeSpeed | float | The game’s sideways speed. It has no effect on movement. |
IsCrouching | bool | true while the player is crouched. |
IsWalking | bool | true when the walk toggle is on (walk mode instead of run mode). |
IsGrounded | bool | true while the player stands on the ground. |
ControlsDisabled | bool | true while the player’s controls are held, including a Lock from this API. |
Things to know
- On the main menu, or with no player, the reads give plain defaults.
IsGrounded,IsCrouchingandIsSprintingarefalse, andVelocityandPositionareVector3.zero. IsSprintingistruewhen the player is set to run, not when they are actually moving. A player who is standing still with run mode selected readstrue. It isfalsewhile crouching. Swimming is not checked. (it istruewhen run speed is the selected speed: not crouching, and either the Walk toggle is in run mode or the input is a controller. The game reads the same condition inGetTargetSpeed. No movement check is made.)IsGroundedandIsCrouchingcome straight from the game’s player controller. (OpenSewerCharacterController.movement.isGrounded(throughBaseCharacterController.isGrounded) andOpenSewerCharacterController.isCrouching.)Velocityis the player’s current velocity, andPositionis the position of the player’s body. (movement.velocityand the controller’s transform position.)WalkSpeed,CrouchSpeed,BackwardSpeedandStrafeSpeedare the controller’s current values.RunSpeedandSwimmingSpeedinclude the orange mushroom’s speed boost. When the orange mushroom effect is not active, they are the unmodified base speeds. (they are the controller’s getter values, which include the game’s orange mushroom run modifier.)IsWalkingistruein walk mode andfalsein run mode. (the controller’s publicwalkproperty is never assigned in the game code, so the privatewalkingfield is read through the same reflection field asIsSprinting.)ControlsDisabledistruewhile anything holds the player’s controls. That includes aLockfrom this API. (it isOpenSewerCharacterController.ControlsDisabled().)- Sprinting is not in
State(). The controller does not expose it, so use theIsSprintingproperty.
Limits
IsAvailabletells you whether the speed changes work. It isfalsewhen the framework could not set up its speed hooks. The multipliers then stop applying. Reads,LockandUnlockkeep working.