Godot 4.3 GDExtension C++ Physics Determinism for Rollback Netcode

Game Development
Date:November 17, 2026
Topic:
Godot 4.3 GDExtension C++ Physics Determinism for Rollback Netcode
⏱ 3 min read

You're building a fighting game in Godot 4.3. Your rollback netcode works locally. Then you test across continents and desyncs explode. The culprit isn't your network code — it's physics non-determinism hiding in plain sight.

Why Physics Breaks Determinism

Godot's built-in PhysicsServer3D uses floating-point math that varies across CPU architectures, compiler optimizations, and even runtime states. A single frame's physics step on x86_64 produces different results than ARM64. For rollback netcode, where every peer must simulate identical frames from identical inputs, this variance is fatal.

"

Determinism isn't a feature you add later. It's a constraint you design for from the first line of physics code.

— Network Physics Engineer

GDExtension: Your Determinism Escape Hatch

GDExtension lets you replace Godot's physics with a C++ implementation using fixed-point arithmetic or deterministic float libraries. You keep the editor workflow, scene tree, and GDScript gameplay code while owning the simulation core.

cpp
// gdextension/physics_server_3d.cpp
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/vector3.hpp>
#include "fixed_math.hpp"

class DeterministicPhysicsServer3D : public PhysicsServer3D {
    FixedVector3 gravity = FixedVector3(0, -980, 0); // 9.8 m/s^2 in fixed-point
    
    void _body_set_state(RID p_body, PhysicsServer3D::BodyState p_state, const Variant& p_variant) override {
        // Store state in fixed-point, ignore Variant noise
        BodyData& body = get_body(p_body);
        body.position = FixedVector3(p_variant);
        body.linear_velocity = FixedVector3(p_variant);
    }
    
    void _body_step(RID p_body, float p_delta) override {
        // p_delta converted to fixed-point ticks
        Fixed32 delta = Fixed32::from_float(p_delta);
        BodyData& body = get_body(p_body);
        body.linear_velocity += gravity * delta;
        body.position += body.linear_velocity * delta;
        // Collision resolution uses fixed-point only
    }
};
💡
TipUse libfixmath or boost::multiprecision::cpp_dec_float for fixed-point math. Avoid std::float_t — its precision varies by platform.

Integration Checklist

StepActionVerification
1Register GDExtension entry pointgodot::GDExtensionBinding::InitObject
2Override PhysicsServer3D methods_body_step, _area_step, _shape_cast_motion
3Replace ProjectSettings physics/3d/singletonYourDeterministicPhysicsServer3D
4Disable built-in PhysicsServer3DProjectSettings -> Physics -> 3d -> Enabled = false
5Test cross-platform frame parityHash frame state on x86_64 and ARM64

Rollback-Specific Patterns

Your deterministic physics server must support snapshot/restore for rollback frames. Implement _body_get_state() returning fixed-point data and _body_set_state() accepting it without side effects. Store the last 64 frames in a ring buffer keyed by frame number.

cpp
// Snapshot for rollback
struct PhysicsSnapshot {
    uint32_t frame;
    std::array<FixedVector3, MAX_BODIES> positions;
    std::array<FixedVector3, MAX_BODIES> velocities;
    Fixed32 accumulator;
};

class DeterministicPhysicsServer3D : public PhysicsServer3D {
    std::array<PhysicsSnapshot, 64> history;
    
    Variant _body_get_state(RID p_body, PhysicsServer3D::BodyState p_state) override {
        BodyData& body = get_body(p_body);
        return Variant(body.position.to_vector3()); // Convert for GDScript
    }
    
    void restore_frame(uint32_t frame) {
        PhysicsSnapshot& snap = history[frame % 64];
        for (int i = 0; i < body_count; i++) {
            bodies[i].position = snap.positions[i];
            bodies[i].linear_velocity = snap.velocities[i];
        }
        accumulator = snap.accumulator;
    }
};
⚠️
WarningNever call Godot's non-deterministic math functions (sin, cos, sqrt) inside physics steps. Precompute lookup tables or use fixed-point approximations.

Testing Determinism in CI

Add a GitHub Actions matrix testing x86_64 and ARM64 runners. Run a headless Godot instance that simulates 10,000 frames with recorded inputs, then hashes the final world state. The hash must match across architectures.

yaml
# .github/workflows/determinism.yml
jobs:
  determinism-test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        arch: [x64, arm64]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Setup Godot 4.3
        uses: firebelley/godot-export@v5
      - name: Run determinism test
        run: godot --headless --script res://tests/determinism_test.gd
      - name: Compare hashes
        run: |
          HASH_X64=$(cat hash_x64.txt)
          HASH_ARM64=$(cat hash_arm64.txt)
          if [ "$HASH_X64" != "$HASH_ARM64" ]; then
            echo "DETERMINISM FAILURE"
            exit 1
          fi

Ship It

You now own the physics simulation. Your rollback netcode compares frame hashes instead of debugging desyncs. Players in Tokyo and São Paulo experience identical hit detection. The GDExtension boundary keeps your gameplay code in GDScript while the deterministic core runs in C++. Next step: profile the fixed-point overhead — it's usually under 2ms per frame — then optimize collision broadphase for your specific game genre.

Share𝕏 Twitterin LinkedInin Whatsapp