Hi there,
I was trying to achieve a destroy effect on my character(a bird, made out of cubes). Every cube gets destroyed by:
this.destroyableParts.forEach(function(entity) {
entity.collision.enable = true;
entity.rigidbody.enabled = true;
entity.rigidbody.applyImpulse(rnd(-this.inpulse, this.inpulse), rnd(-this.inpulse, this.inpulse), rnd(-this.inpulse, this.inpulse));
}.bind(this));
All good, but, I am not able to reset the cubes position/rotation.
I tried with setLocalPosition(), setPosition(), teleport() but none seemed to work.
NOTE: Because I use this as a death effect, the rigid body gets enabled only when the player dies. It gets deactivated back when player respawns. All cubes have 0 velocity on respawn so it’s not like they keep moving.
Here is the restore function:
this.destroyableParts.forEach(function(entity) {
entity.rigidbody.enabled = false;
entity.collision.enabled = true;
//entity.rigidbody.teleport(entity.script.destroyable_part.initialPos);
entity.setLocalPosition(entity.script.destroyable_part.initialPos);
entity.setLocalEulerAngles(entity.script.destroyable_part.initialRot);
entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
entity.rigidbody.angularVelocity = pc.Vec3.ZERO;
console.log('x: ' + entity.script.destroyable_part.initialPos.x + ',y: ' + entity.script.destroyable_part.initialPos.y + ',z: ' + entity.script.destroyable_part.initialPos.z);
}.bind(this));
Initial Position/Rotation are stored like this:
this.initialPos = this.entity.getPosition();
this.initialRot = this.entity.getLocalEulerAngles();
Any thoughts? Thanks!