terminalCode Example

Noclip MoveMode with Collision Toggle

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Noclip MoveMode Implementation

Custom movement mode for noclip/fly behavior with collision toggle.

CSHARP
using Sandbox.Movement;

public sealed class NoclipMoveMode : Sandbox.Movement.MoveMode
{
    [Property] public bool EnableCollision { get; set; }
    [Property] public float RunSpeed { get; set; } = 1200;
    [Property] public float WalkSpeed { get; set; } = 200;

    public override int Score(PlayerController controller) => 1000;

    public override void UpdateRigidBody(Rigidbody body)
    {
        body.Gravity = false;
        body.LinearDamping = 5.0f;
        body.AngularDamping = 1f;
        body.Tags.Set("noclip", !EnableCollision);
    }

    public override void OnModeBegin()
    {
        Controller.IsClimbing = true;
        Controller.Body.Gravity = false;

        if (!IsProxy)
            Sandbox.Services.Stats.Increment("move.noclip.use", 1);
    }

    public override void OnModeEnd(MoveMode next)
    {
        Controller.IsClimbing = false;
        Controller.Body.Velocity = Controller.Body.Velocity.ClampLength(Controller.RunSpeed);
        Controller.Body.Tags.Set("noclip", false);
        Controller.Renderer.Set("b_noclip", false);
    }

    public override Vector3 UpdateMove(Rotation eyes, Vector3 input)
    {
        input = input.ClampLength(1);
        var direction = eyes * input;

        bool run = Input.Down(Controller.AltMoveButton);
        if (Controller.RunByDefault) run = !run;

        var velocity = run ? RunSpeed * 2.0f : RunSpeed;
        if (Input.Down("walk")) velocity = WalkSpeed;

        if (Input.Down("jump")) direction += Vector3.Up;
        if (Input.Down("duck")) direction += Vector3.Down;

        return direction * velocity;
    }

    protected override void OnUpdateAnimatorState(SkinnedModelRenderer renderer)
    {
        renderer.Set("b_noclip", true);
        renderer.Set("duck", 0f);
    }
}

Key Patterns

Was this helpful?