moisesjpelaez - Add fixedUpdate for Physics

This commit is contained in:
Onek8 2025-06-01 23:09:47 +00:00
parent a6d9cb9201
commit cfbe7c83cb

View File

@ -136,10 +136,10 @@ class PhysicsWorld extends Trait {
conMap = new Map();
active = this;
// Ensure physics are updated first in the lateUpdate list
_lateUpdate = [lateUpdate];
@:privateAccess iron.App.traitLateUpdates.insert(0, lateUpdate);
// Ensure physics are updated first in the fixedUpdate list
_fixedUpdate = [fixedUpdate];
@:privateAccess iron.App.traitFixedUpdates.insert(0, fixedUpdate);
setDebugDrawMode(debugDrawMode);
iron.Scene.active.notifyOnRemove(function() {
@ -298,7 +298,7 @@ class PhysicsWorld extends Trait {
return rb;
}
function lateUpdate() {
function fixedUpdate() {
var t = Time.delta * timeScale;
if (t == 0.0) return; // Simulation paused
@ -312,9 +312,9 @@ class PhysicsWorld extends Trait {
var fixedTime = 1.0 / 60;
//This condition must be satisfied to not loose time
var currMaxSteps = t < (fixedTime * maxSteps) ? maxSteps : 1;
var currMaxSteps = t < (Time.fixedStep * maxSteps) ? maxSteps : 1;
world.stepSimulation(t, currMaxSteps, fixedTime);
world.stepSimulation(t, currMaxSteps, Time.fixedStep);
updateContacts();
for (rb in rbMap) @:privateAccess rb.physicsUpdate();