[f8] Line of site, raycasting and realistic visability

Ever notice how if your sitting in a room, and theres a wall in front of you, you cant see whats on the other side of that wall (and if you can, you should be here…)

I’m working on a version of icio’s “Point-to-Point Line-of-Site” Thingy.

Think: Top down guy walking around in a building, with multiple rooms. He cant see whats in the room (since like I said, the walls are in the way), though, he can see into the room through the open dooor, but only a small part of it (since the door is only a thin opening in what is an otherwise large room.)

What I want to do is make realistic, dynamic lighting, based on (I would assume) raycasting or lone of sight or some similar godlike power.

I edited Icio’s demo with MSPaint showing what I am talking about. I’ve been thinking about ways to do it and have thought of a few different ways that would be, for the most part, processor intensive by searching around for visable points based on our hero’s position and what he can “see”

Any one have any ideas for an easy(for the processing computers atleast) way to do this?

:glasses:

Do you mean…

Each block casts a shadow as if the player was a point light? ( or lightbulb). Thus whenever he moves the shadow is cast at a different angle?

Got to say thats a very cool problem to have!

Sounds like Draw API + trigonometry to me.

how would you like to define objects in a room
as images (pixels) or vectors (points)

bootiteq: Thats it exactly. I knew I’d be using draw api to draw in the shadows, but not sure how to figure out where to draw without checking 360 degrees around the player ever frame (I think it would be too slow)

gvozden: I’ve recreated Icio’s line of sight thing using just one movie clip of obsticles to make blocks for the line of sight. But I’m compleatly open to changing it based on however the best way to do the shadow casting.

that is far too complicated for me Psykloak1.

I would suggest however that it would be easiest to create a shadow for each block independently, rather than considering the whole combined shape.

It would also seem as though the furtherest two points were the only ones you would need to figure out based on your game world boundary coordinates.

check out http://gamasutra.com/ for inspiration

however in my experience of making a game I found it easier to consult a basic school textbook for trig functions. Cause it was well written and and easy to follow

Bootiteq, you gave me an idea for a new way to fake it. This is is basically what I want, but I’d rather have it done with math and the draw api.

In this fake (attached), I have a movie clip that is the shadow and in it is a shape tween from what it would look like when you are far away to what it would look like if your up close. it then goes to and stops at whatever frame based on distance with the mouse and rotates accordingly aswell.

Hopefully I’ll be able to think of a better way, to do it without faking it… this is just a quick thing i threw together so its a bit crappy, I’d make a better version if I’ have to do it this way.

I did this fla on a mac, flash mx. hope theres no problem opening it on other systems

wow Psykloak1 thats cool!

Thanks, thats what I want it to look like, though I really dont want to fake it like I did there.

I’ve made another attempt. This one shoots out lines in multiple directions and then draws in the shadow from the points where each of the lines impacts an obsticle. Now, the more lines it uses, the more accurate the shadow will be. However, at the same time, the more lines it uses, the slower the whole thing goes.

What I see when I run it with, like, 150 or 200 lines, Theres so many lines that are not important. The only important lines are the ones that go from corners of objects to the charecter.

Attached are four test runs at four different numbers of lines, 16, 32, 64 & 128 (they dont have to be powers of 2, I’m just keeping them organized)

Any suggestions?

Another attempt. I’ve defined the corners with empty movieclips and drawn lines from them away from the hero. Now I have to figure out how to make the think know which lines to draw intop a black fill poligon. I could have a list of predefined points that are conencted but i’d rather not have to pre program it that much

as I remember it there are some functions performed like does point belong to rectangle
using that kind of function can help you a lot
it was 5 years from when I had Geometry for informatics on University :slight_smile:

I still like


the best

had a wee play just now with alpha and modify/shape/soften edges

frame rate seems good too :elderly: