Godot 4.3 GDExtension C++ Physics Determinism for Rollback Netcode
Game Development
Date:November 17, 2026
Topic:
⏱ 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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-pointvoid_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
Step
Action
Verification
1
Register GDExtension entry point
godot::GDExtensionBinding::InitObject
2
Override PhysicsServer3D methods
_body_step, _area_step, _shape_cast_motion
3
Replace ProjectSettings physics/3d/singleton
YourDeterministicPhysicsServer3D
4
Disable built-in PhysicsServer3D
ProjectSettings -> Physics -> 3d -> Enabled = false
5
Test cross-platform frame parity
Hash 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Snapshot for rollbackstruct 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);
returnVariant(body.position.to_vector3()); // Convert for GDScript
}
voidrestore_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.
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.