moisesjpelaez - Add fixedUpdate for Physics

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

View File

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