Visibility test.

I need to do some visibility test to implement node based path finding. I don’t know the exact name of it, but the idea I have in mind is this.

  • Developer places movement nodes around the map by hand, in a certain manner so that every node can see at least one another node;
  • When doing movement, check if destination point is visible. If it is, just walk to it in a straight line;
  • If it isn’t do some kind of node based pathfinding algorithm and work out shortest node path to destination point, or something like that…

One big problem I can see incoming is checking if the node is visible. I have node idea how to do it properly. Here is a simple illustration showing what I want to accomplish if you don’t understand…

On one of my previous games I implement vision by doing something like this:

  • Pick a starting point and destination point. Compute x,y increments so each increment is of specific length, lets say increment length = 1;
  • Add those increment values to starting position, until starting position is equal to destination position;
  • After each increment check if current position on the level is a visible point. If not, the path is not visible.

I guess this is called ray casting or something like that. The problem I see coming with this already is that it would be reallllyyyyyyyy slow if I computed visibility check many times. Are there better ways to compute visibility, or should I also calculate which nodes are visible by a certain node before the game begins so that each nodes know which nodes it can see, since those nodes wouldn’t change positions.

There is using A*. You can set each node to the corner of each object and use A* to check for the path around those nodes. It is a very flexible algorithm not just used for tile based systems.

Hmm I found this page somewhere. I think I will try to implement path smoothing from this page first, since it is far less work, because I already have A* implemented in my game.

EDIT---------------
Lets just come back to the original question which is what is the best way to do visibility test (is it called ray casting?).

Write a line-line intersection function first. Then intersect your line-of-sight with the 4 lines comprising the edges of your rectangle.

[s]Thanks I’m trying to write line intersection method.

I’m reading this wiki page, and I don’t seem to understand one thing.

I’m kinda stuck at calculating proper intersection point. I’m kinda confused. The page says that we can find the intersection point by using determinants. The thing I don’t get is why is intersection point’s P coordinates x,y found by the same ‘method’. Is it me or is intersection point P.y always the same as X? The formula to calculate P.y is the same as the formula to calculate P.x

Is this wiki page’s fault, or am I missing something here?[/s]

EDIT-------------
Ignore the post I just made :smiley: I can’t read, it so seems.