Dear,
I have a problem, it happens that I have a box that crashes against a wall and other boxes, this is through an impulse applied to the box.
My problem is that by applying the same impulse, the box does not always end up in the same place.
What can be?
My code is as follows:
For the box
var Dado1 = pc.createScript(‘dado1’);
// initialize code called once per entity
Dado1.prototype.initialize = function() {
var app = this.app;
this.initialPos = this.entity.getPosition().clone();
this.initialRot = this.entity.getRotation().clone();
app.on('dado1:reset', function () {
this.entity.setPosition(this.initialPos);
}, this);
app.on('dado1:activarImpulso', function () {
this.entity.rigidbody.applyImpulse(0, 0, -20);
}, this);
};
Dado1.prototype.update = function(dt) {
};
To activate the pulse:
var BtnStates = pc.createScript(‘btnStates’);
// initialize code called once per entity
BtnStates.prototype.initialize = function() {
var app = this.app;
I’m guessing that it looks similar but not exactly the same? Physics uses a lot of randomness when working out what to do in the case of collisions, especially multiple collisions occurring at the same time. At the end of the day you would use Ammo (like here) or PhysX (in Unity) to do real world scientific simulations with stable outputs, they run quickly for game engines and produce a realistic output.
Does that sound like it might be the case or is it more extreme? Do you need it to be exactly the same for some reason, or could we come up with a way of circumventing that?
Also you probably need to make sure that there are no other forces or velocities on these objects from previous frames. Might even be worth trying to clone these entities and destroy the old ones.
Thank you very much for your help, I did everything and it does not work for me.
Each time I throw the dice they are different.
I attach the link so that you can see it
If you look into _updateKinematic you’ll see it’s just PlayCanvas updating the transform of an Entity using regular dt. It doesn’t do any fixed timestep steps in there.
On the other hand stepSimulation is called on ammo which I believe performs additional update loops internally depending on the difference between the dt that is passed to it vs the fixed dt.
In any case I don’t think that’s the problem here because the dice are not kinematic but dynamic. My guess is that ammo is not deterministic.
Well judging from your example there since it’s different everytime you refresh the application I’m guessing that ammo is not deterministic. Ammo is a javascript port of the Bullet physics engine. You could do some research into how you can make Bullet deterministic and if you find a method then we have to see if that’s exposed in ammo.