Is it possible for an entity to detect collisions of entities that are not the one detecting it?

I’m trying to make an enemy like the Gigadora in Metroid, where it has multiple points where the player has to hit multiple points to defeat it, but I cannot figure out how to make the main entity detect when its child entities are touched. All three points need to be hit for the enemy to be defeated. The reason why the script shows another thing is because there is another form of the enemy with only one point, but it requires a missile(Which hasn’t been implemented yet, but will be added soon, once I finish adding something else)

Can someone fix the problem?

Script:PlayCanvas | HTML5 Game Engine

The scene where I’m testing it out is Sector 1: PlayCanvas | HTML5 Game Engine

Hi @Linkplayer!

Each collision entity is part of the enemy, so when one gets hit it can either look up its parent or simply fire an event to the parent.

You could give each collision entity its own script, which directly communicates with a parent script.

By the way, if I’m correct you don’t need to have multiple scripts, because you can listen to a collision event on a different entity. Something like below.

Listen to collision event on the first child entity:

this.entity.children[0].collision.on('collisionstart', this.onCollisionStart, this);

Looking at your script, you already do this but I don’t think touch is an existing event. Keep in mind the initialize function is only called at start.

I didn’t want the player to interact with the individual eyes, so I only gave them collision and not a rigid body.

So, wouldn’t I want to check for “triggerenter” and not “collisionstart”?

Oh, wait, I did “touch” and not “triggerenter”. I’ve just changed “touch” to “triggerenter”, but I’m not going to test it until I’m done with English, so…

I hope this works. I most likely won’t be able to test it this week.

1 Like

Also, I found that Initialize should be used for events like colliding with objects for if you only need it to interact once per collision, because it’ll play through for one frame, but another interaction will play it again. On the other hand, if you put it in “Update,” instead of playing once, I find it to play multiple times a frame. I went from full health to dead in 3-6 frames (I don’t really know; it wasn’t instantaneous, but it was almost instantaneous) from standing on a damage tile. I had it so that it did 1 damage every hit, and I had 99 HP, so it did about 17-33 hits every frame.

That’s right. I was referring to your statements, not your events, sorry for the confusion. You can also use your statements in the initialize function, but I tried to say that they are only read at start and not at every collision.