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.
Printable View
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.
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.
Please use the search functions as there are many threads and also examples available.
Extension:
http://www.triplezap.com/extensions/
Example:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=194709
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 like the idea blurymind, thanks for bringing it up.
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)
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
Doesn't that just measure distance though?Quote:
Originally Posted by Gustav
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.
Got it to work, thanks guys.