The Daily Click ::. Forums ::. Klik Coding Help ::. Top Down Shooter Line of Sight
 

Post Reply  Post Oekaki 
 

Posted By Message

G. Hull



Registered
  07/01/2009
Points
  125

Wii Owner
27th September, 2010 at 17:01:26 -

Okay guys, picture this.
I've got a the player, who is on the left of the screen. I've got a turret, on the right of the screen. And I've got a wall, in between the player and the turret. The player is able to move around the wall to get to the turret. Important part: I want the turret to see the player within a certain radius of itself, assuming he's in his line of sight. So if the player is behind the wall, the turret cannot see him.

Got that, everyone?
Thanks!

 
n/a

Knockturnal

Nothing to see here turn back

Registered
  11/04/2008
Points
  354

VIP Member
27th September, 2010 at 22:19:46 -

You can have an active object that is it's "radius" or you can just check the distance using this formula:
Sqr( ((X( ">Player<" )-X( ">Turret<" )) Pow 2)+((Y( ">Player<" )-Y( ">Turret<" )) Pow 2) )

Which will calculate the distance between the two objects.

As for the wall I suggest running a similiar technique as you would use to make a laser in a game using fastloops.
Can't remember the exact code for this one, but it's basically a line that resizes itself lenghtwise and checking for collissions using a fastloop. Just make it invisible and make it point at the player (using the 360 degree angle, offcourse). So when line hits player = can be seen. If player is inside radius but not colliding with line = hidden.

Maybe someone can explain the latter part somewhat better



EDIT: I'm sure you can constrain the line so it will work as the radius too. Sorry If I'm not making any sense

Edited by Knockturnal

 
Professional vaporware developer

Rick Shaw



Registered
  30/04/2008
Points
  158
27th September, 2010 at 23:53:32 -


Originally Posted by Coca-Cola Man

As for the wall I suggest running a similiar technique as you would use to make a laser in a game using fastloops.
Can't remember the exact code for this one, but it's basically a line that resizes itself lenghtwise and checking for collissions using a fastloop. Just make it invisible and make it point at the player (using the 360 degree angle, offcourse). So when line hits player = can be seen. If player is inside radius but not colliding with line = hidden.

Maybe someone can explain the latter part somewhat better



I remember reading this particular article, I think. Let's see if I can summarize it off the top of my head:

To test line-of-sight, you create an object that is just a single pixel on the turret. The pixel is rotated to the angle between the turret and the player (use a calculation or the advanced movement object), and a fastloop is started for something like a few thousand loops.

In the fastloop, once per loop the x scale of the line-tester-object is increased by 1. Then, it tests to see if it's overlapping a backdrop, or obstacle object, or whatever. If it is, it quits the loop and returns "no line of sight." Otherwise, it keeps looping until it overlaps the player, and quits and returns "yes line of sight".

I think that's it, based on what I remember. I never tried it, I did L-O-S with a much clunkier and slower way. Find the article for more specifics. The distance calculation given above is correct.

 
n/a

G. Hull



Registered
  07/01/2009
Points
  125

Wii Owner
28th September, 2010 at 01:15:39 -

That helps me...but I'm still stuck. I honestly have no idea to code any of this (Although I've tried). I would really appreciate it if one of you could point me in a closer direction, or give me the basic step-by-step process. Hope that's not to much to ask.

Much appreciated,
Rannug

 
n/a

Rick Shaw



Registered
  30/04/2008
Points
  158
28th September, 2010 at 06:16:54 -

here we go, it's part 3 of this article http://www.create-games.com/article.asp?id=2137

 
n/a
   

Post Reply



 



Advertisement

Worth A Click