☑ Destroy entity when linearVelocity is zero

Hello, i want my bullet to be destroyed when it stops so i thought

if (this.entity.rigidbody.linearVelocity === pc.Vec3.ZERO) {
    this.entity.destroy();
}

but don’t work…

You need:

http://developer.playcanvas.com/en/api/pc.Vec3.html#equals

if (this.entity.rigidbody.linearVelocity.equals(pc.Vec3.ZERO)) {
    this.entity.destroy();
}

Thanks @will i knew it was some stupid mistake i did :stuck_out_tongue:

Hello, sorry to revive this topic but now always the arrows are destroyed when they stops…and since the collision component works also when the arrow lay on floor and someone steps on it, i really need to make it disappear, i think that’s vec3 problem that’s not accurate am i right? If so i think i can check the distance from arrow and player and if greater than the weapon range it’s destroyed. Let me know what u think.

The vec3.equals() should be accurate. The question is if it is too accurate for your needs.If some steps in the arrow, are both positions EXACTLY the same? If not, vec3.equals() is not the right solution as it checks if both vectors have the exact same values.

Your solution of checking range is the right way to go for this.

Tnx @steven i thought so