Destoying from scene exhibits all youngsters deleted, however nonetheless childrens are seen in scene on collision : –
On collision with the noticed, that is occurring : –
onLoad() {
this.animationComponent = this.node.getComponent(Animation);
this.animationComponent.clips[0].title = AnimationNames.IDLE;
this.animationComponent.clips[1].title = AnimationNames.RUN;
this.animationComponent.clips[2].title = AnimationNames.DANCE_1;
this.animationComponent.clips[3].title = AnimationNames.DANCE_2;
this.characterBody.getComponent(RigidBody).useCCD = true;
this.characterBody
.getComponent(BoxCollider)
.on("onCollisionEnter", this.onCollisionEnter, this);
}
onCollisionEnter(occasion: ICollisionEvent) {
const otherColliderName = occasion.otherCollider.title;
const selfColliderName = occasion.selfCollider.title;
if (otherColliderName.contains("Floor-Mesh")) {
// Deal with Floor-Mesh collision
} else if (otherColliderName.contains("ramp")) {
// Deal with ramp collision
} else if (otherColliderName.contains("noticed")) {
console.log("noticed", this.node.getParent().youngsters);
this.node
.getParent()
.getComponent(CharactersManager)
.removeCharacter(this.node); // Make sure you cross the right node
} else if (otherColliderName.contains("knife")) {
// Deal with knife collision
} else if (otherColliderName.contains("hammer")) {
// Deal with hammer collision
} else if (otherColliderName.contains("LeftSide")) {
// Deal with LeftSide collision
} else if (otherColliderName.contains("RightSide")) {
// Deal with RightSide collision
}
}
From this, name goes to the mother or father i.e. –
removeCharacter(character: Node) {
const characterUUID = character.uuid;
let characterToBeRemoved = null;
// Discover the character to be eliminated
for (let i = 0; i
On the finish, full array is consoled as empty array, however childrens are nonetheless seen within the scene. What’s occurring mistaken with the collision detection code? How am i able to repair this ?
You’ll be able to add breakpoints within the two features, node.destroy
and node.setParent
, after which observe by way of debugging whether or not these features are being executed, and in addition examine if the node
that’s being operated on is the one you anticipate.
Thanks for replying, Truly i obtained the error, Its due to the the beneath code solely. Factor occurring was it was eradicating 2 nodes at a time, however solely destoying 1 node at a time. Forgot that destoying a node removes it from its mother or father additionally.
// Destroy the character node
nodeToRemove.destroy();
// Take away from characters array
// this.characters.splice(characterToBeRemoved.index, 1);
// Replace youngsters depend
// this.charactersCurrentlyInScene--;
// Take away from mother or father node's youngsters array
// if (nodeToRemove.mother or father) {
// const indexInChildren =
// nodeToRemove.mother or father.youngsters.indexOf(nodeToRemove);
// if (indexInChildren !== -1) {
// nodeToRemove.mother or father.youngsters.splice(indexInChildren, 1);
// }
// }
Simply commented the final code, and it labored superb.