Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Ammo: Not all entities/bodies remove on collision event (issue with remove entities) #137

Open
smeybi opened this issue Jun 25, 2019 · 4 comments
Labels

Comments

@smeybi
Copy link

smeybi commented Jun 25, 2019

Hi,
I noticed something, I'm not sure if it's a issue, maybe I'll remove entities the wrong way.

I would like to remove entities at collision. The collide events work, but if i use this for removeChild, not all entities are removed. It's look like a rhythm, a few are skipped.

This is the collision event code:
this.el.addEventListener('collidestart', function(e) {
if (remove_e) {
e.target.parentNode.removeChild(e.target);
} else {
e.target.setAttribute('color', "blue");
}

Here is a example (only collisions with static bodies) on glitch, when a button is pressed, it will change to remove entity or color change:
https://glitch.com/edit/#!/aframe-physics-ammo2

The same example with dynamic bodies it works, but I think it works, because there are many collisions events, that finally remove the entity.
https://glitch.com/edit/#!/aframe-physics-ammo1

Edit: The same issue is when removing entities direct, not on the collision event. The collisions events skip some entities.

@smeybi smeybi changed the title Ammo: Not all entities/bodies remove on collision event Ammo: Not all entities/bodies remove on collision event (issue with remove entities) Jun 26, 2019
@donmccurdy donmccurdy added the bug label Jul 21, 2019
@ghost
Copy link

ghost commented Feb 11, 2020

When using AmmoDriver, removing objects with removeChild will prevent "collidestart" and "collideend" of the remaining objects.
Is there any other way to delete the object with Ammo-body added?

(edit) post new issue
#141

@smeybi
Copy link
Author

smeybi commented Jul 13, 2021

Try after a long time, I found out, it has a problem with deleting the ammo body on remove the entity (with ammo physics). I recreated and combined it with three.js. It work until remove the entity. For example it works, remove the ammo body and the object3D separate, not problem
document.querySelector('a-scene').systems.physics.driver.removeBody(e.target.body)
e.target.object3D.parent.remove(e.target.object3D)

But remove the entity there were the dropouts again.
e.target.parentNode.removeChild(e.target)

I figured out, if this Ammo.destroy(this.body) is exchanged with the this.system.driver.removeBody(this.body) in the script for the Ammo remove function, it works. I don't know if this causes problems anywhere else!
I hope the information helps more to find the problem!

aframe-physics-system.js Line 14912:

remove: function() {
if (this.triMesh) Ammo.destroy(this.triMesh);
if (this.localScaling) Ammo.destroy(this.localScaling);
if (this.compoundShape) Ammo.destroy(this.compoundShape);
if (this.body) {
this.system.driver.removeBody(this.body) //Ammo.destroy(this.body);
delete this.body;
}
Ammo.destroy(this.rbInfo);
Ammo.destroy(this.msTransform);
Ammo.destroy(this.motionState);
Ammo.destroy(this.localInertia);
Ammo.destroy(this.rotation);
},

@aussieburger
Copy link

Try after a long time, I found out, it has a problem with deleting the ammo body on remove the entity (with ammo physics). I recreated and combined it with three.js. It work until remove the entity. For example it works, remove the ammo body and the object3D separate, not problem document.querySelector('a-scene').systems.physics.driver.removeBody(e.target.body) e.target.object3D.parent.remove(e.target.object3D)

But remove the entity there were the dropouts again. e.target.parentNode.removeChild(e.target)

I figured out, if this Ammo.destroy(this.body) is exchanged with the this.system.driver.removeBody(this.body) in the script for the Ammo remove function, it works. I don't know if this causes problems anywhere else! I hope the information helps more to find the problem!

aframe-physics-system.js Line 14912:

remove: function() { if (this.triMesh) Ammo.destroy(this.triMesh); if (this.localScaling) Ammo.destroy(this.localScaling); if (this.compoundShape) Ammo.destroy(this.compoundShape); if (this.body) { this.system.driver.removeBody(this.body) //Ammo.destroy(this.body); delete this.body; } Ammo.destroy(this.rbInfo); Ammo.destroy(this.msTransform); Ammo.destroy(this.motionState); Ammo.destroy(this.localInertia); Ammo.destroy(this.rotation); },

Legend figuring that out and posting it! Was banging my head for days trying to figure out why that was happening :)

@wujiiu
Copy link

wujiiu commented Nov 4, 2022

Is there any progress pls?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants