RPG Maker MZ

RPG Maker MZ

Events Line of Sight Player Detection
Hi!
I'm trying to make events that can detect the player by sight. That is, they shouldn't detect the player if there is a wall in the middle. So far I can make them detect the player if they are close and facing them but not having any luck with the walls impeding the detection.
Would be great if there is a plugin for this, free or paid.
Thanks in advance for any help :)
< >
Showing 1-4 of 4 comments
coyote_craft May 12, 2022 @ 11:28pm 
I draw rooms and elevations with different region ids. And use a script call for conditional branch evaluations. Something like,
this.regionId() == $gamePlayer.regionId()

So the even if the event is triggered it's not going to do anything unless their region Ids match.
This is handy for "touch" events where the player might be on a cliff and a monster is standing on the tile next to them, but "below". They're suppose to be on different elevations.
Last edited by coyote_craft; May 12, 2022 @ 11:29pm
Mazinkaiser_DX May 13, 2022 @ 1:08pm 
Yes!
I was thinking something with regions but didn't know how to code it.
Sadly, with that script it wasn't working so I tried separating it and storing the values in variables to see what was the issue, the player's regionId is being stored just fine but the events' is always zero so I'm guessing it's missing something.
Using a control variables command in the event's page with the script "this.regionId()" as the variable's value running on parallel. =/
coyote_craft May 17, 2022 @ 4:42pm 
Try replacing this.regionId() with $gameMap._events[this._eventId].regionId()

"this" can mean different things depending on where the script command is. I believe this.regionId() would work if it was used inside the event's move route. Because there, "this" is the event itself as part of the Game Map. But in the event command list, "this" is the game interpreter that processes the event's commands. So we have to be a little more specific about what we're pointing to.

Edit: Or, use the specific ID number like, $gameMap._events[8].regionId()
Last edited by coyote_craft; May 17, 2022 @ 11:23pm
Caethyril May 20, 2022 @ 9:47am 
The Get Location Info command lets you store an event's region ID in a variable:
◆Get Location Info:#0030, Region ID, This Event

If you want true line-of-sight, that's typically done by rasterising the line to the tile grid (e.g. Bresenham algorithm) then iterating through the resulting tiles to check if any of them block the line. It's not super complicated, but you'd definitely want a plugin for it. There's this one for MV, haven't tested it in MZ:
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: May 12, 2022 @ 6:19pm
Posts: 4