Is it possible to make Line Of Sight can detect obstacle without plugins ?

So I want to implement the A* (Pathfinding) and Line Of Sight algorithms for my thesis.

Which is where the enemy will detect and chase the player when it enters the range of the Line Of Sight and also I want to make the enemy able to detect obstacles, so if the player hides behind an obstacle the enemy will stop chasing and also the enemy will stop chasing if the player manages to escape from range.

Note : I want to make this without a plugin.

Pseudocode example:

If Player Gets into enemy range
Turn on alert audio and balloon icon then Chasing Player
if else Player hides behind obstacles or get out from the LOS range
Enemies stop chasing players
else
Enemies move randomly

Is it possible to make code like the one above in the form of a script call on a custom movement route?
Yes it is possible. Atleast the Sight Detection... Pathfinding algorithms are not my Field of expertise.

I cant find the Line of Sight Tutorial at the moment, it showcased many different Line of Sight possibilities to create with standard Event System.
With or with out the help of Scriptlines. Maybe someone else remembers the Tutorial and finds the Link.

What kind and range of Sight do you envision?
Note : I want to make this without a plugin.

make code like the one above in the form of a script call
I think you are under a misconception of what a script call is and what a plugin is.

The entire engine is a single script.
A script call is something that calls a part of that script. You do not code a script call because that code already exists.
And a plugin is a method to add more code and script to the engine.

Now the default code for pathfinding is not the best. If you want a better code, then you basically have to use a plugin to add that better pathfinding to the engine, and after that you can make a script call to the plugin functions to use them.
Oh, oke. So i have to make my own plugins. Thanks for the answer
Found it, it is for VX-Ace but its convertible to the other RPG Makers and it should explain the Basics of this.
Maybe it helps getting you further with this task...
Found it, it is for VX-Ace but its convertible to the other RPG Makers and it should explain the Basics of this.
Maybe it helps getting you further with this task...

I think this is only Line Of Sight. It doesn't include obstacle detection script.
It doesn't include obstacle detection script.
of course not, because the map has no definition for sight obstacles at all, you would have to define that for yourself.
because you can't use passability for that - a chasm would block move but not sight for example.

you could theoretically define that yourself by using terrain tags, but that is not easy.
there is an perfect line in sight plugin with detecting obstacles detection
which will be ignored.

Gimmer_SpottingPlayers might be able to do what you want, maybe you
need to re-structer some things to make it work in the way you want too,
but it should do the trick for what you want.
As Andar implied, RMMV already implements 12-tile basic A* pathfinding for its touch-based player movement: Game_Character#findDirectionTo.

Line-of-sight in a tile-based context involves line rasterisation (e.g. Bresenham). There is no implementation of this in the core scripts.

This is the plugin I usually recommend for LoS in RMMV:
...but if it's for your thesis then I assume you can't use that. In that case I'd recommend getting familiar with the core scripts, to identify appropriate method hooks. E.g. Game_Event#update, which updates the event every frame.
I guess it would be best, trying to solve complicated stuff like this, which also contains many unknown details, only step by step.

Which Line of sight do you like best?
Next step after deciding that, is to think about the view blocking obstacles.
But the solution for that could change depending on which kind of sight you choosed.
I've been using bresenham's line algorithm to detect if the line of sight intersects with a region.

Spoiler: Code
Game_Map.prototype.collectRegionsBLA = function(x0, y0, x1, y1)
{
const ra = [];
const dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
const dy = Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
let err = (dx>dy ? dx : -dy)/2;
while (true)
{
const rId = this.regionId(x0, y0);
if (rId > 0) ra.push(rId);
if (x0 === x1 && y0 === y1) break;
const e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
return ra;
};
I guess it would be best, trying to solve complicated stuff like this, which also contains many unknown details, only step by step.

Which Line of sight do you like best?
Next step after deciding that, is to think about the view blocking obstacles.
But the solution for that could change depending on which kind of sight you choosed.

I want triangle vision.

Oh yeah, so try to understand a little about the YEP_ChasePlayer and GALV_EventDetector plugins.

For the YEP_ChasePlayer, I'm still confused about the function clearChaseSettings. It contains the property that I was looking for through the Kinoar library and it's not there. like this._ alertBalloon. I also opened rpg_objects.js and didn't find it either. Was that property just created inside the function or did he actually access it from something else?

For the GALV_EventDetector there is a line of sight. So he blocked it using 2 ways, namely numbering with terrrain tags and regions. However, when I read the program, it was quite long and a bit difficult to understand.

I hope I can make a combination of the two plugins XD
You mean like this?

facing-right-triangular-los.png
You mean like this?

facing-right-triangular-los.png
Yes Triangle vision but can all direction not just facing
I've been using bresenham's line algorithm to detect if the line of sight intersects with a region.

Spoiler: Code
Game_Map.prototype.collectRegionsBLA = function(x0, y0, x1, y1)
{
const ra = [];
const dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
const dy = Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
let err = (dx>dy ? dx : -dy)/2;
while (true)
{
const rId = this.regionId(x0, y0);
if (rId > 0) ra.push(rId);
if (x0 === x1 && y0 === y1) break;
const e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
return ra;
};
How to use this ?
How to use this ?
The function returns an array of Regions that are intersected by the line (x0,y0,x1,y1).
It was made for MZ but it should be able to be modified for MV.

I'm using it with the triangle line of sight and check for no regions-
Code:
◆If:Script:Math.abs($gameMap.event(this._eventId).x - $gamePlayer.x) + Math.abs($gameMap.event(this._eventId).y - $gamePlayer.y) <= 3
  ◆If:Script:$gameMap.event(this._eventId).direction() == 2 && $gameMap.event(this._eventId).y < $gamePlayer.y || $gameMap.event(this._eventId).direction() == 8 && $gameMap.event(this._eventId).y > $gamePlayer.y || $gameMap.event(this._eventId).direction() == 4 && $gameMap.event(this._eventId).x > $gamePlayer.x || $gameMap.event(this._eventId).direction() == 6 && $gameMap.event(this._eventId).x < $gamePlayer.x
    ◆If:Script:$gameMap.collectRegionsBLA($gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y, $gamePlayer.x, $gamePlayer.y).length===0;
      ◆Show Balloon Icon:This Event, Exclamation (Wait)
      ◆
    :End
    ◆
  :End
  ◆
:End
The function returns an array of Regions that are intersected by the line (x0,y0,x1,y1).
It was made for MZ but it should be able to be modified for MV.

I'm using it with the triangle line of sight and check for no regions-
Code:
◆If:Script:Math.abs($gameMap.event(this._eventId).x - $gamePlayer.x) + Math.abs($gameMap.event(this._eventId).y - $gamePlayer.y) <= 3
  ◆If:Script:$gameMap.event(this._eventId).direction() == 2 && $gameMap.event(this._eventId).y < $gamePlayer.y || $gameMap.event(this._eventId).direction() == 8 && $gameMap.event(this._eventId).y > $gamePlayer.y || $gameMap.event(this._eventId).direction() == 4 && $gameMap.event(this._eventId).x > $gamePlayer.x || $gameMap.event(this._eventId).direction() == 6 && $gameMap.event(this._eventId).x < $gamePlayer.x
    ◆If:Script:$gameMap.collectRegionsBLA($gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y, $gamePlayer.x, $gamePlayer.y).length===0;
      ◆Show Balloon Icon:This Event, Exclamation (Wait)
      ◆
    :End
    ◆
  :End
  ◆
:End
So this code will make line of sight block when pointed on obstacles, am i right ?
So this code will make line of sight block when pointed on obstacles, am i right ?
If you use regions to mark your obstacles.
If you use regions to mark your obstacles.
Oh okey, i get it. Oh yeah can i ask one more question.

I just looked at the RPG Maker MV Library and I'm confused there are property like x,y then _x, _y and realX, realY

what is the difference between those three ? (Sorry for my bad english)
x,y and _x,_y are mostly the same as variables.
the realX and realY unsure, but that is probably checking pixel x,y and ore images.

I know some plugin using it to track the player movement to be more precise and location.
but I cannot tell the exact reason behind it though.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-make-line-of-sight-can-detect-obstacle-without-plugins.152866/