Grounders

Grounder base class and concrete grounder components — detect ground contact, compute ground normals and slope data, and drive mode switching on the MoverContext.

Grounders run each physics tick to determine whether the unit is in contact with the ground, what the slope looks like, and whether the surface is walkable. They write their findings to the MoverContext and switch movement modes when the ground state changes.

For usage guides and setup examples, see The Basics: GS_Unit.

Grounder component in the O3DE Inspector

 

Contents


Class Hierarchy

GS_GrounderComponent (base — mode-aware activation, tick management)
  └── GS_PhysicsRayGrounderComponent  (grounding mode: "Free")

GS_GrounderComponent (Base)

Tick: AzPhysics::SystemEvents::OnPostSimulateEvent (after the physics step).

Mode-Aware Activation

Listens to MoverContextNotificationBus::GroundingModeChanged. Compares the broadcast mode name against its own m_groundModeName. Calls ToggleGrounder(true/false) accordingly. The physics post-simulate handler is only registered when the grounder is active.

Per-Tick Processing

Each tick:

  1. CheckCanOperate() — validates required pointers and state
  2. HandleGrounding() — performs ground detection and updates MoverContext (no-op in base)

Key Fields

FieldDescription
m_groundModeNameGrounding mode string this grounder activates for
deltaCached frame delta time

Concrete Grounders

ComponentGrounding ModeDescription
GS_PhysicsRayGrounderComponent"Free"Raycast-based grounder with coyote time, slope detection, and manual gravity

API Reference

Virtual Methods

Override these when extending any grounder:

MethodParametersReturnsDescription
ToggleGrounderbool onvoidCalled when the grounding mode activates or deactivates.
HandleGroundingvoidCalled each tick when the grounder is active. Override to implement ground detection logic.
GroundingStateChangeAZ::u32 newStatevoidCalled when ground contact state changes. Override to react to grounding transitions.
CheckCanOperateboolReturns true if the grounder has everything it needs to run this tick.

Consumed Buses

BusEventDescription
MoverContextNotificationBusGroundingModeChanged(modeName)Activates or deactivates this grounder based on mode name match.

Produced Calls

BusMethodDescription
MoverContextRequestBusSetGroundNormal(normal)Updates the ground normal used by the MoverContext for input projection.
MoverContextRequestBusSetContextState("grounding", value)Sets grounding state: 0 = Falling, 1 = Grounded, 2 = Sliding.
MoverContextRequestBusChangeMovementMode(modeName)Switches to "Slide" when slope exceeds maxWalkAngle, or back to "Free" on recovery.

Extension Guide

Use the Grounder ClassWizard template to generate a new grounder with boilerplate already in place — see GS_Unit Templates. The template offers two base class options: Physics Ray Grounder (default, includes raycast, coyote time, and gravity) or Base Grounder for fully custom detection.

Extend GS_GrounderComponent to implement custom ground detection.

#pragma once
#include <Source/Unit/Grounder/GS_GrounderComponent.h>

namespace MyProject
{
    class MyGrounder : public GS_Unit::GS_GrounderComponent
    {
    public:
        AZ_COMPONENT_DECL(MyGrounder);
        static void Reflect(AZ::ReflectContext* context);

    protected:
        void Activate() override;

        void HandleGrounding() override;
        void GroundingStateChange(AZ::u32 newState) override;

    private:
        // Set in Activate():
        // m_groundModeName = "Free";
    };
}

In HandleGrounding(), run your detection and write results to the MoverContext:

void MyGrounder::HandleGrounding()
{
    AZ::Vector3 groundNormal = AZ::Vector3::CreateAxisZ();
    bool isGrounded = false;

    // ... custom detection logic ...

    GS_Unit::MoverContextRequestBus::Event(
        GetEntityId(),
        &GS_Unit::MoverContextRequestBus::Events::SetGroundNormal,
        groundNormal
    );

    AZ::u32 state = isGrounded ? 1 : 0;
    GS_Unit::MoverContextRequestBus::Event(
        GetEntityId(),
        &GS_Unit::MoverContextRequestBus::Events::SetContextState,
        "grounding", state
    );
}

See Also


Get GS_Unit

GS_Unit — Explore this gem on the product page and add it to your project.