# Overview

<figure><img src="/files/kmcqC9lbcTuUnj7XDyaU" alt=""><figcaption></figcaption></figure>

Replicated Gravity provides a networked, authority-driven custom gravity solution for characters, vehicles, and physics-simulated objects. It integrates directly into Unreal Engine's movement pipelines (CharacterMovement and Chaos Physics) to ensure high-performance, predictable results in any orientation.

The system is designed Iris-first with seamless fallback to legacy property replication and is fully Double-Precision (LWC) optimized for stability in massive worlds.

It ships with a custom falling model for characters that keeps replicated animations correct when gravity direction changes, especially in Planetary and Dynamic modes.

All gravity and rotation logic for characters is integrated through Unreal's movement update hooks (`UpdateCharacterStateBeforeMovement`, `UpdateCharacterStateAfterMovement`), making it performant, deterministic, and easy to integrate.

Built for Unreal Engine 5.6+ and uses the engine's native `SetGravityDirection()` so client prediction and server authority share the same gravity every frame—no custom `FSavedMove_Character` code required.

{% embed url="<https://www.fab.com/listings/6189790c-1ad3-4e02-b977-83794d4d1e97>" %}

<p align="center">Get it on Fab</p>

{% embed url="<https://discord.gg/X9bJSMkDtW>" %}

<p align="center">Support Discord</p>

### Key Features

#### **Planetary, Directional, Dynamic, & Zero Gravity Modes:**

**Planetary:** Gravity pulls toward a configurable center point (planets, asteroids, small planetoids).

* Direction computed as `(Center - CharacterLocation).GetSafeNormal()`
* Updates during movement via `SetGravityDirFromState()`
* Singularity-safe at exact center
* Smooth quaternion rotation with lerp final alignment

**Directional:** Gravity uses a constant down vector for gravity rooms, wall/ceiling walking, and rotated spaces.

* Explicit world-space direction
* No traces required
* Deterministic and authority-driven
* 0.5° update throttling for network efficiency

**Dynamic:** Multi-probe system that detects nearby surfaces for wall/ceiling walking.

* Head Probe: Sphere sweep for ceiling detection
* Movement Probes: Four diagonal sweeps for wall detection
* Feet Probe: Two-stage anchor and capsule confirmation system. Tracks raw unsmoothed gravity direction for improved precision on curved and rotating surfaces
* Opt-in Predictive Probe System: Dual wall probes and a ledge drop probe classify what's ahead in real time, driving smooth wall and ledge transitions automatically with full hysteresis for flicker-free results
* Collision Channel Integration: Uses dedicated user-defined trace channel for precise control
* Priority Resolution: Head > Movement > Feet (ceiling catch highest priority)
* Velocity Reprojection: Prevents "kick" effect during gravity transitions
* Moving Platform Support: Local-space swivel caches last valid feet hit in component space and reconstructs in world space each frame to track rotating surfaces

**Zero Gravity:** Full weightlessness mode for space environments, puzzles, and zero-g gameplay.

* `EnterZeroGravity` and `ExitZeroGravity` Blueprint callable functions
* Fully replicated with local prediction for responsive feel
* `bZeroGravityActive` and `bExternalFlyingActive` for clean integration with custom flying setups
* `ZeroGravityExitGravityScale` for full control over gravity restoration on exit
* `ExitZeroGravity` is idempotent — safe to call unconditionally from any overlap
* Flying rotation pipeline fully preserved entering and exiting zero gravity

Switch modes and update parameters at runtime via Blueprint or C++.

#### Native `SetGravityDirection()` Support (UE 5.6+)

Uses Unreal Engine 5.6's built-in `SetGravityDirection()` so the client's predicted move and the server's authoritative simulation share the same gravity each frame.

* No custom `FSavedMove_Character` required
* No `SavedMove` serialization needed
* Clean integration with standard `CharacterMovementComponent`

#### Double-Precision & LWC Ready

Full support for Large World Coordinates (UE 5.6+):

* When `bUseHighPrecisionMath` is enabled, the system treats the character as a temporary origin for `FVector3d` calculations, ensuring maximum accuracy regardless of world position.
* All internal math uses double precision
* Rotation logic is LWC-safe
* No jitter millions of units from world origin
* Stable on planet-scale environments

#### Authority-Driven Gravity for Multiplayer

Server is the single source of truth:

* Gravity mode, center, and direction replicated to all clients
* Owning client predicts movement locally for responsive controls
* Simulated proxies receive rotation corrections
* Designed from the ground up for networked gameplay

**Network Flow**:

* Server: Computes gravity direction, replicates state
* Owning Client: Predicts movement, sends input to server
* Simulated Proxies: Receive `ReplicatedComponentRotation` in `TickComponent()`

#### Iris-Ready With Automatic Fallback

Uses Iris replication where available for efficient, modern networking:

* Automatic fallback to traditional property replication if Iris not enabled
* Iris support self-contained to this plugin
* Iris itself remains optional

**Replication**:

```cpp
#if UE_WITH_IRIS
RegisterReplicationFragments()  // Modern Iris path
#else
GetLifetimeReplicatedProps()    // Legacy fallback
#endif
```

#### Animation-Friendly Custom Falling Model

**Supplemental Safety Net**:

* 5-point line trace system (center + 4 cardinal offsets)
* Keeps characters grounded on jagged/poor collision
* Distance controlled by `FloorDetectionTolerance` (default: 100 units)
* Only activates when standard floor check fails

**Dual Falling State**:

* `bPredictedIsFalling`: Locally controlled characters (responsive input)
* `bReplicatedIsFalling`: Remote clients (animation sync)
* Custom `GetIsFalling()` function returns correct state per context

**Why This Matters**:

* Standard `IsFalling()` only works for Z-down gravity
* Custom `GetIsFalling()` works for arbitrary gravity directions
* Prevents animation breaks during gravity transitions

#### Tick-Free Movement Integration

Gravity and falling logic integrated through movement hooks:

* `UpdateCharacterStateBeforeMovement()`: Computes gravity direction
* `UpdateCharacterStateAfterMovement()`: Updates falling state, replicates rotation
* `TickComponent()`: Only for simulated proxy rotation fixes

**Not Using**:

* Custom per-frame Tick() code
* Heavy computation outside movement pipeline

**Benefits**:

* Predictable performance
* Consistent with Unreal's standard `CharacterMovementComponent`
* Clean, maintainable code

#### Blueprint-First Controls

All gravity parameters exposed as Blueprint variables:

* `GravityMode` (Enum: Directional, Planetary, Dynamic)
* `GravityCenter` (Vector: Planetary mode)
* `GravityDirectionVector` (Vector: Directional mode)
* `DynamicGravityTraceChannel` (Collision Channel: Dynamic mode)

**Visual Debugging**:

* `bShowVisualDebugs`: Toggles system-wide visual debugging
* Shows probe locations, hit points, rotation methods
* On-screen messages for active rotation path
* Essential for tuning Dynamic mode

#### Advanced Features

**Moving Platform Visual Fix**:

* `bApplyReplicatedRotationOnMovingBases`: Fixes client visual desync on rotating platforms
* Tracks base quaternion deltas in `UpdateBasedRotation()`
* Applies gravity-aligned yaw compensation
* Visual-only (no physics impact)

**Gravity-Aligned Flying**:

* `bApplyGravityRotationWhileFlying`: Enables rotation during flying mode
* Smooth interpolation in `UpdateCharacterStateBeforeMovement()`
* Preserves forward direction while aligning to gravity
* Works with all gravity modes (Full rotating surface support while flying is in development and coming in a future update)

**Rotation Constraints**:

* `SetGravityRotationMode(Default)`: Free rotation
* `SetGravityRotationMode(ForwardBack)`: Pitch-only (around right vector)
* `SetGravityRotationMode(LeftRight)`: Roll-only (around forward vector)
* Applied during quaternion stepping

**Vehicle Gravity System (v2.6.0 New)**

* **Networked Chaos Integration**: `UGravityVehicleMovementComponent` inherits from `UChaosWheeledVehicleMovementComponent`, providing authority-driven gravity for Chaos vehicles.
* **Ground Hold System**: Integrated inward acceleration logic helps keep vehicles seated on curved planetary surfaces at speed.
* **Dynamic Up-Alignment**: A torque-based alignment system smoothly rotates the vehicle's up-axis toward the gravity vector with adjustable stiffness and damping.
* **Gravity-Aware Sleep**: Custom sleep logic (`bUseGravityAwareSleep`) allows vehicles to rest naturally on arbitrary slopes without sliding or jittering.
* **Vehicle Controller**: `AGravityVehicleController` handles Enhanced Input mapping, HUD spawning, and smart camera configuration for gravity-aware driving.

**Planetary Physics Gravity (v2.5.0)**

Physics objects now respond to the same planetary gravity as characters — fully integrated into the existing field system.

* bApplyPhysicsGravity on any BP\_GravityField enables custom planetary gravity for overlapping physics-simulated objects
* Gravity is applied in a Chaos pre-tick callback for accurate, frame-level force application
* Physics loop uses ParallelFor for high active object counts with lock-free game thread to physics thread communication
* Custom sleep gate with tunable velocity and acceleration thresholds — sleeping objects cost nothing per frame
* UGravityReceiverComponent — optional component for multi-body actors, ragdolls, and actors that need authoritative sleep state or replicated ragdoll correction
* UGravityReplicationSubsystem — world subsystem providing O(1) body registration, unregistration, and sleep-state tracking across all active fields
* Off by default — fully backwards compatible, existing projects are unaffected

#### Third Person / First Person Support

Includes separate character setups:

* **Third Person**: Optimized rotation smoothing for third-person camera
* **First Person**: Controller rotation integration with gravity alignment
* Both with example animation blueprints

#### **Example-Ready Gameplay Setup**

**Included Content:**

* Fully configured third-person and first-person gravity characters
* Separate game mode Blueprints for each perspective
* Dedicated `GravityField` Blueprint (Planetary, Directional, Dynamic)
* Example levels: `Example_Lvl_ThirdPerson`, `Example_Lvl_FirstPerson` and `Example_Lvl_Vehicle`

#### **Technical Highlights**

**Rotation System**

* Quaternion Stepping: For large angle changes (smooth, axis-constrained)
* Lerp Smoothing: For final alignment in Planetary/Dynamic modes
* Instant Snap: For Directional mode when within tolerance
* Max Step: `RotationSpeed` \* `DeltaTime` (clamped to 90°)
* Tolerance: `RotationStopTolerance` controls snap threshold
* Independent tunable speeds for every Dynamic transition type — wall, ledge, surface, enhanced smoothing, and head-probe rotation

**Dynamic Gravity Probes**

* Head: Sphere sweep for ceiling detection
* Movement: Four diagonal sweeps for wall detection
* Feet: Two-stage anchor and capsule confirmation system. Tracks raw unsmoothed gravity direction for improved precision on curved and rotating surfaces
* Ot-in Predictive Probe System: Dual wall probes and a ledge drop probe classify what's ahead in real time, driving smooth wall and ledge transitions automatically with full hysteresis for flicker-free results
* Local-Space Swivel: Last valid feet hit cached in component space, reconstructed in world space each frame to track rotating surfaces
* Settle Frames: 5-frame delay before clearing proposals on movable bases

**Network Optimization**

* Quantization: `FVector_NetQuantizeNormal` for directions, `FVector_NetQuantize10` for centers
* Update Throttling: 0.5° threshold (`Gravity_ShouldUpdateDirection`)
* Conditional Replication: `COND_SkipOwner` for falling state and rotation
* Client Prediction: Local immediate response with server RPC confirmation

**Performance Characteristics**

* Per-Frame Cost (Dynamic mode):
  * Grounded: up to 5 collision checks (anchor sphere + capsule confirmation + up to 3 forward probe sweeps for wall and ledge classification)
  * Airborne with head proposal active: 1 check (head sphere only, movement and feet skip)
  * Airborne standard: up to 7 checks (head + 4 movement + anchor + capsule)
* No Tick(): All logic in movement hooks
* Deterministic: Same results on server and client prediction
* Scalable: Efficient for large player counts

***

### System Requirements

* Unreal Engine 5.6+
* Supports Iris replication (optional)
* Compatible with standard ACharacter
* Works with CharacterMovementComponent pipeline
* LWC/Double-Precision ready


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://replicated-gravity.gitbook.io/replicated-gravity-docs/home/overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
