I found this code somewhere on a forum and it sounded like it would be what I’m looking for, but it seems to be called way to frequently and always before my entities begin to move.
This line doesn’t do a value copy, it just copies the reference so both variables now point to the same Vec3 object.
Assuming that this.dice[i].lastPos is already a Vec3, then you would want:
this.dice[i].lastPos.copy(this.dice[i].currPos);
This line also doesn’t check by value, it just compares references:
this.dice[i].currPos === this.dice[i].lastPos
Comparing floating points for equal value generally doesn’t work due to floating point inaccuracy so you should check if the distance between the two points is lower than x. eg:
var d = new pc.Vec3();
d.sub2(this.dice[i].currPos, this.dice[i].lastPos);
if (d.lengthSq() < 0.01) {
// Do something
}
Of course, since you are using physics, if you really want to know if something has stopped moving, you can check the rigid body’s velocity and if it’s below a certain value or 0, it has stopped moving.