forked from LeenkxTeam/LNXSDK
moisesjpelaez - Add fixedUpdate for Physics
This commit is contained in:
@ -136,10 +136,10 @@ 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);
|
||||||
|
|
||||||
iron.Scene.active.notifyOnRemove(function() {
|
iron.Scene.active.notifyOnRemove(function() {
|
||||||
@ -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();
|
||||||
|
Reference in New Issue
Block a user