This project has moved and is read-only. For the latest updates, please go here.

RayCasting and vision of sight, need help in understanding

Mar 9, 2011 at 4:37 PM

so i googled and searched, and this is what i got mean while.

there is an option to send a line (raycasting) and find out every object that in his way with the option of that object to block this ray

iv heard it is poissible to use it to check what one can see which is what im trying to create

problem is im not sure how. i need to create so many rays to cover every space that my char can see? or how exacly

more over im not really sure about the code when using raycasting so if you could help me a bit with that as well id really apprecciate it

so basicly im trying to create a small arcade game with the charcter in complete darkness and that she can see only in the vision of the mouse

that would be easy with drawing a black on all the other things.. problem is i want to be able to hide objects behind other objects.. and here is when iv looked and found about raycasting

yet not sure how to use it...

thankyou in advance!!!!


Mar 10, 2011 at 12:18 PM

If you only want to hide objects graphically, and do nothing related to the game's logic, you should take a look to Krypton Engine which is a project that makes the graphical effect you are describing.

Mar 10, 2011 at 1:04 PM


thanks for it!

ill check it out~! :)

Mar 10, 2011 at 1:39 PM

ok first of all thanks~!

now i need to find how exacly to fuse it with farseer . (is there anyone who have done it by any chance?)

but i have another question. if i do want to add logic in case of seeing/not seeing. what can i do?

thanks again!


Mar 10, 2011 at 1:48 PM

For the first question, you should create the hulls with the same polygon vertices you want to use for occlusion. Check the sample over there.

For the second question, what I do is to cast three rays: one for the furthest vertice, another for the closest, and another for the fixture's center (which usually is the body's position in my game). Is not perfect, but the chances that the fixture is visible are low when all the three raycasts find an obstacle.