Page 1 of 1

Line of Sight Demo - (can I see the bad guy ?)

PostPosted: Sat Aug 02, 2008 2:09 am
by feral
This is a quick and dirty but easy way to create line of sight, for example - to test if your player can actually see an item/enemy

in the attached screen-grab the "blue" player "cannot " see the skull
LOSgrab.jpg
screengrab
"player CANNOT see skull"

LOSDemo.zip
ged and data files
(105.44 KiB) Downloaded 240 times


it basically tests for the existence of walls between the player and whatever he needs to see.

It work by drawing on a canvas (hidden) and testing if the line intersects (collides) with a wall

you can see HOW it works, by deleting the actor "floorblock". (which hides the canvas)

restrictions:

1. it gets confused when used on "cloned" wall blocks.. for some reason it thinks it can sometimes see between them, even if they are stacked tight. so instead, I had to create a solid MAP overlay - see the file backdrop.png to see what I mean

to see the issue, delete or move the "backdrop" image off screen and leave only the original cloned wall sprites.

I have not tested it with tiles yet.. but it should work !?!?!? let us know if you test it...

if any one can fix this glitch ? let me know..

2. it uses canvas's :( so it is really only good for testing for 1 item or 1 enemy, but, it still should be useful in some games..

eg can my SAM missile actually see the helicopter to lock-on... or, hide and seek with a monster etc etc

I am planning a more complex version ( without canvas's ) soon

feral

Re: Line of Sight Demo - (can I see the bad guy ?)

PostPosted: Sat Aug 02, 2008 3:15 am
by DST
i always send an actor from the looker to the target and ask what the actor collided with on the way. If the actor is the same size as whatever shot will be fired, it will give a very accurate reading.

Re: Line of Sight Demo - (can I see the bad guy ?)

PostPosted: Sat Aug 02, 2008 3:48 am
by feral
i always send an actor from the looker to the target and ask what the actor collided with on the way. If the actor is the same size as whatever shot will be fired, it will give a very accurate reading.


I agree :D that is the best way... but it takes quite a few frames to do ?? or did I make a boo-boo and miss something :oops:

:lol:
but yeah, the way you describe is definitely a good way to do it, unless you need to do a new check every screen draw

The only other way I could do it in a "single" screen draw, was with collision free , but then I don't know what I collided with :?

this was just a way to do a separate check on "every screen draw" for a fast moving enemy.. ....