 1. ## Line of sight

Is there a way to determine if there is a clear line of sight between two objects?

For instance, the enemy only shoots if there's nothing in-between it and the player.  Reply With Quote

2. Try shooting an invisible object which gets destroy when hitting anything but the player. If it reaches the player there's a line of sight.  Reply With Quote

3. Please use the search functions as there are many threads and also examples available.

Extension:

http://www.triplezap.com/extensions/

Example:  Reply With Quote

4. you can create an active object and call it line. Make the object track the enemy and at the same time stretch to the player. This can be done with an expression on the line of sight object:

set position to enemy

set X scale:
0.0 + Sqr(( ( X( "player" ) - X( "Enemy" ) ) pow 2 ) + ( ( Y( "player" ) - Y( "Enemy" ) ) pow 2 ) ) / 10.0

set angle:
ATan2(Y( "Enemy" ) - Y( "player" ), X( "player" ) - X( "Enemy" ) )

If the stretching line of sight object is overlapping a background wall, then player is not visible
if stretching line of sight object width > X, then player is too far to be seen.

Hope this helps.

There was an example file burried somewhere, but I forgot where.  Reply With Quote

5. I like the idea blurymind, thanks for bringing it up.  Reply With Quote

6. Originally Posted by blurymind you can create an active object and call it line. Make the object track the enemy and at the same time stretch to the player. This can be done with an expression on the line of sight object:

set position to enemy

set X scale:
0.0 + Sqr(( ( X( "player" ) - X( "Enemy" ) ) pow 2 ) + ( ( Y( "player" ) - Y( "Enemy" ) ) pow 2 ) ) / 10.0

set angle:
ATan2(Y( "Enemy" ) - Y( "player" ), X( "player" ) - X( "Enemy" ) )

If the stretching line of sight object is overlapping a background wall, then player is not visible
if stretching line of sight object width > X, then player is too far to be seen.

Hope this helps.

There was an example file burried somewhere, but I forgot where.
I don't understand what sqr or pow does, but I'll try it.  Reply With Quote

7. Sqr is Square Root and Pow is to the Power of
They're most often used in triginometry to find the length of the hypotenuse in a triangle, it's commonly known as the distance formula.

a^2 + b^2 = c^2
rearrange to find c
c = sqr(a^2 + b^2)  Reply With Quote

8. You can replace this formula with an inbuilt expression from the Special object:

Distance(>X of first point<, >Y of first point<, >X of second point<, >Y of second point< )

(Special > Distance and Angle > Distance between two points)

Here is a quick example: Attachment 13916  Reply With Quote

9. Originally Posted by Gustav
You can replace this formula with an inbuilt expression from the Special object:

Distance(>X of first point<, >Y of first point<, >X of second point<, >Y of second point< )

(Special > Distance and Angle > Distance between two points)

Here is a quick example: line_of_sight.mfa
Doesn't that just measure distance though?  Reply With Quote

10. Which is what you're trying to achieve, set the X scale of the object to the distance between the two objects

If distance is this: A_________B
Don't you want your object to do this: AOOOOOOOOOB

The rotation ensures it's always looking in the direction of the enemy, and if you always set it's x&y coordinates to the player it will follow the player.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•