How do I use raycasting to stop seeing through walls?

Hello guys, I’m trying to make a 2d dungeon crawler but I’m having some trouble with the player being able to see through walls and seeing enemies on the other side. I’ve tried using a light object to follow the player and if it comes in collision with an enemy it changes the ememy’s opacity from 0 to 255, but then I noticed that even though it was showing that the light wasnt going through the walls it still changed the opacity of the enemies to 255 if the player was close enough to the enemy through a wall. The game has randomly generated rooms and hallways that connect to eachother, so I’m not able to place things in the scene, everything is generated in the events and placed randomly.

I’m trying to make it where the player can only see enemies if they are at a certain distance AND if there are no walls between the players line of sight. I’ve tried using raycasting since the light thing didn’t work, but I have no idea what I’m doing wrong. I’ve tried looking at other people’s posts regarding that same topic, but I can’t figure out how to use the raycasting to:

  1. pick an object it sees
  2. Change the opacity of picked object if it’s an IceElemental
  3. If it picks a wall, then don’t show the IceElemental

I have the IceElemental and the Wall in the same group too if that helps

I’m very confused and would appreciate any and all help


If a wall is hit by the raycast first, then no IceElemental will be selected, and the subevents are not actioned.

If the raycast hits an IceElemental first, then only that one is selected and in scope for the event and its subevents (like the repeat event). All other IceElemental objects are ignored. So the one hit will be referenced in the repeat subevent. It will be the only one picked, so it’s tint will be set to 255;255;255. All other IceElementals are not processed.

So that repeat is redundant - there will only be 1 IceElemental to repeat over.

I think what you’re trying to achieve is tint the IceElemental darker if it’s not spotted by the player, and lighter while it is in the player line of sight. If that’s the case, try the following events in place of what you have:


And I’ve raycast form the centre of the player, rather than the top left (unless the player origin has been moved)