Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing physics object unlinks visuals and physics #385

Open
CrushedPixel opened this issue May 16, 2024 · 1 comment
Open

Removing physics object unlinks visuals and physics #385

CrushedPixel opened this issue May 16, 2024 · 1 comment

Comments

@CrushedPixel
Copy link

Describe the bug
Removing an object from the physics scene disconnects the visual representation of objects from its physics. I am using ammo physics.

Code:

this.foodItems.forEach((item) => {
  this.scene.remove(item)
  this.physics.destroy(item.body) // <-- removing this line fixes the issue
})

Issue:
https://github.com/enable3d/enable3d/assets/10288753/4b19302d-bbae-479d-9951-849f31f59832

INTENDED BEHAVIOR can be observed when only deleting the scene object, not the physics object:
https://github.com/enable3d/enable3d/assets/10288753/62bb2605-14c2-42b6-b09e-6396fbfe4c17

@CrushedPixel
Copy link
Author

CrushedPixel commented May 17, 2024

After digging through the source, I found that this is because all of my enable3d objects have the default name 'Scene', which is copied to the btRigidBody in addRigidBodyToWorld. Therefore, there is no distinction between the physics objects in the rigidBodies array, therefore the following code just deletes all entries from rigidBodies.

for (let i = 0; i < this.rigidBodies.length; i++) {
if (this.rigidBodies[i].name === name) {
this.rigidBodies.splice(i, 1)
i--
}
}

It seems like object id should always be used here for identification.

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

No branches or pull requests

1 participant