Hi everybody,
what I am trying to achieve is simulating a physics scenario only in-memory (without rendering) and taking note of the position of my object in an array for each step of the simulation. The simulation has complex collisions, so it is not possible to use math formulas of some sort.
I tried to use the step function, outside the update method, but the position of the object does not change of an inch:
const { world } = this.physics;
world.on("worldstep", () => { // this callback is correctly invoked
console.log(ball.x); // it does not change
});
for (let i = 0; i < 10000; i++) {
world.step();
// world.update(0, world._frameTimeMS); // I tried also this, but no difference
}
I tried with both arcade.customUpdatetrue and false.
Is what I am trying to do even possible with Phaser?
I isolated the relevant part of the code, such that the behaviour changes only if I change the customUpdate config option. The two resulting arrays are completely different. Do you see something wrong?
Step operates on physics bodies only. You need to read the body coordinates to see the results. Also body coordinates and game object coordinates are distinct so you can’t compare them directly. I didn’t notice that in the code above, sorry.
If you want to match how the scene works when custom update is off, you need to use update + postUpdate instead of step, that’s true.
To me, this smells as something is wrong with the World step method. Or, as I tend to think, its purpose is not the one that a developer can interfere from the official documentation.
The step method should be basically considered as internal, and the developer should be provided with a more straightforward method, called singleStep, which does what one could expect. Hence the pull request.