How to make object visible when collide with light?

I was making a top down shooter game. I want to make the enemy is invisible and inactive at the beginning of the scene. But after the player’s light touch the enemy, it will become visible and actively move to the player or start shots the player. How to make it possible? Thanks

At the beginning of the scene
Hide Enemy
Activate Behavior: No
If Player Light is in collision with Enemy
Show Enemy
Activate Behavior: Yes

Something like this may work but I don’t know if light in GDevelop has a collision mask.\

Edit: So, if light doesn’t have a collision mask then we can make a sprite with its origin point on centre then change the x and y position of that sprite to light’s x and y position.

After that, check if Player Light Collision Sprite is in collision with Player
Show Enemy
Activate Behavior: Yes

Light doesn’t have a collision mask, so that won’t work.

Your best move would be to make a sprite with a collision box that is the same shape as the torch light. Attach it to the player sprite so that it rotates with the player.

Upon a collision between this sprite and the enemy sprite, make the enemy visible.

Only move the enemy if it’s visible, i.e. have a parent event with condition that checks the enemy is visible, then the subevents of that event will only apply to visible enemies.

@MrMen it’s a good idea but you have to manage the light obstacle. I suggest you to manage the raycast

@jumpingj, yes, good point. So the sprite collision first, and then a raycast to any enemies that are in the collision to confirm they’re not obscured by a light obstacle.

1 Like