Progress towards next big Clashflash update:
AuthorMessage
>> Flash & ActionScript > ActionScript > Line of sight
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
Hi.

i dont know if this is a small or a big question beacuse
im not very good at the math things.

im looking for a line of sight for my enemies and not just a "line" but more a triangle i already tried to make it but then it was getting in trouble with the walls and stuff.

if you guys know a tutorial or some math to do this i would like to hear it bigsmile

Greetings

Reaven


picture
Myth
avatar
Administrator
Level: 99 - Posts: 477
Joined: Dec 9, 2006
I think this is a complex question if I understand your problem well.
You want to have a (visible?) line of sight triangle for the enemies, but when they're close to a wall you don't want the line of sight to overlap the wall if I'm correct.

This is certainly not my cup of tea, but I found a little something for you:
http://sc.tri-bit.com/Computing_LOS_for_Large_Areas


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
lol. I'm quite sure he's not going to be able to implement it the way they do over there. You're right myth, it is quite the complex issue. If you want to do it reaven I'm afraid you're stuck with it not being blocked by walls. The only thing you could probably realize considering wall interaction is that you do it the following way:

You attach a view range movieclip to your enemies in the form of a triangle. You use that triangle to hittest the player in order to find out if the player has been spotted. This is a bit tricky since in order to let a triangle hittest something you're going to have to do a pointwise hittest. So like: triangle.hitTest(player._x,player._y,true). (keep in mind though that this is a very simplified way of putting it).

Now you could move those triangles around using a script to let the enemies look around instead of always looking in the same direction. That would require some additional coding.

If adding to that you'd want to let walls block sight you'd need to do some more advanced coding for the moving around of those triangles and that can be quite a hassle.

Of course there are other ways of doing it but in the end none of them is very easy.


"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
AH.. right

is there something/way to this on my level? wink

Greetings


picture
Mennez
avatar
Administrator
Level: 99 - Posts: 1479
Joined: Dec 10, 2006
The triangle way Crisis just said.


picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
but crisis also said that wassent easy too
but i already tried something like that.
but i could do it like attaching it to a enemy then hittest through an array but how do i know that way wich enemy his line of sight i have hit?
thats the tricky part of this


picture
JC-Gamer
avatarposts
Perfect Deity
Level: 35 - Posts: 1004
Joined: Oct 27, 2007
I don't know how to program using ActionScript but I have basic knowledge of Turing and Visual Basic.

Couldn't you make a triangle like Crisis said and then specify that if any part of it hits a solid object that piece of the triangle goes missing and the resulting shape (aka the triangle missing a chunk) becomes a new object (and becomes the new line of sight)?

Like I said, I don't know ActionScript or Flash but if what I said makes sense and you don't get it, I could draw a picture.

Greetings

JC-Gamer tongue


Genesis 3:15-17 "And God said,'Let man be created in my image and have power over everything on earth. Brawl, Mario Kart, and even Legend of Zelda are yours to master and control..."
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
thanks for the reply JC.

i know what you mean but i think in flash that shloud be done with bitmaps[like in worms destroying the ground]
but im not that good in flash to do that and flash doesnt have solid or not solid objects[as far as i know]

Greetz


picture
Mennez
avatar
Administrator
Level: 99 - Posts: 1479
Joined: Dec 10, 2006
Bitmaps?


picture
Myth
avatar
Administrator
Level: 99 - Posts: 477
Joined: Dec 9, 2006
The best way to do it is with a lot of maths.


picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
i was afraid of that..

now i got like a circle around the enemy with math and if you come closer than that pixels he attakcs you for example.... if i only could make that script dont go through walls..

Greetz


picture
Myth
avatar
Administrator
Level: 99 - Posts: 477
Joined: Dec 9, 2006
Maybe you could do so what you said:
reaven said:
now i got like a circle around the enemy with math and if you come closer than that pixels he attakcs you for example.... if i only could make that script dont go through walls..

And then draw an invisible line between the enemy and the player. Hit test with this line so you can check whether there are objects in between. Remember that the hit test should not be one with a box around the line, because that makes diagonal checks impossible. I'm not sure if such a check (hit test) exists in the standard library of actionscript.


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
Well you can do a shape focused hittest, but only if you hittest a shape with a single point. You can't hittest a shape with another shape like that. This would result in flash hittesting the bounding boxes around the shapes.


"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
soo.. i need to draw a line from every enemy to the player and if the line hittests awall the line becomes like disabled or deletes and if the line hittests the player i can do the actions this way i dont need a circle but the enemy has eyes in his back this way and can look like 10.000 miles far.

soo much problems and to less skill sjeesh this is hard im glad i have flash on school lol dunno but that wont help me with this stupit things all the time.. [ and now make a square speechless ]

couldt you guys give me like something so i can learn all this? with draw line functions and stuff? i would realy appreciate that bigsmile bigsmile flashcompetition

Greetz



picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
Hi.

i got a line of sight now! bigsmile with some help of mennez wink

and this with no math at all!

but i only got 2 problems left now bigsmile

the line of sight is a triangle but it is a movieclip
so flash makes it a square so i doesnt hittest the triangle but the movieclip around it.

and the line of sight goes trough walls.

i hope you can help me with these 2

Greetz


picture
< Go to page: 1, 2 >
There are a total of 3152 Clashflash.com members who have posted 7266 articles. Our newest registered user is Hooooda7, welcome!
There are currently 11 users online of whom 0 logged in and 11 guest(s).
auto ban