diff --git a/app/ecs/components/collider.js b/app/ecs/components/collider.js index 6241c81..947ffcc 100644 --- a/app/ecs/components/collider.js +++ b/app/ecs/components/collider.js @@ -38,6 +38,14 @@ export default class Collider extends Component { return distance(entity.Position, l) > distance(entity.Position, r) ? -1 : 1; }); } + destroy() { + const entity = ecs.get(this.entity); + for (const otherId in this.collidingWith) { + const other = ecs.get(otherId); + delete entity.Collider.collidingWith[other.id]; + delete other.Collider.collidingWith[entity.id]; + } + } isCollidingWith(other) { const {aabb, aabbs} = this; const {aabb: otherAabb, aabbs: otherAabbs} = other; diff --git a/app/ecs/ecs.js b/app/ecs/ecs.js index 491d815..8a47672 100644 --- a/app/ecs/ecs.js +++ b/app/ecs/ecs.js @@ -233,12 +233,14 @@ export default class Ecs { } destroying[componentName].push(entityId); } - this.$$entities[entityId] = undefined; - this.diff[entityId] = false; } for (const i in destroying) { this.Components[i].destroyMany(destroying[i]); } + for (const entityId of entityIds) { + this.$$entities[entityId] = undefined; + this.diff[entityId] = false; + } } get entities() {