The Daily Click ::. Forums ::. Klik Coding Help ::. cone of sight.
 

Post Reply  Post Oekaki 
 

Posted By Message

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
31st August, 2007 at 15:22:59 -

I'm trying to do cone of sights this way: I've got a PLAYER and an ENEMY. This line of sight is to determine weather or not an ENEMY is visible to the PLAYER.

Always
- PLAYER alterable value A = the angle the player is currently looking in
- ENEMY alterable value A = the angle from PLAYER to ENEMY

So, ignoring obstacles and stuff:

ENEMY alterable value A - 45 < PLAYER alterable value A
ENEMY alterable value A + 45 > PLAYER alterable value A
- ENEMY is visible

Problem?

ENEMY alterable value A = 0
PLAYER alterable value A = 350

technically the enemy should be visible but according to the formula, it isn't. I've thought about using radians but my head started to hurt. Anyone have an elegant solution to this?

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
31st August, 2007 at 15:49:38 -

Hmm, off hand, I'd say wrap the player/enemy angle value around after it's more than 180 degrees off from each other. I assume you're fastlooping these events, because you'd need to check each enemy individually.

 
Craps, I'm an old man!

Ski

TDC is my stress ball

Registered
  13/03/2005
Points
  10130

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!KlikCast HelperVIP MemberWii OwnerStrawberryPicture Me This Round 28 Winner!PS3 OwnerI am an April Fool
Candy Cane
31st August, 2007 at 16:44:39 -

Destroyer(Crobasoft) made an article I'm sure

Here we are, I'm not even sure if it's what you're looking for

http://www.create-games.com/article.asp?id=1761

Image Edited by the Author.

 
n/a

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
1st September, 2007 at 02:46:11 -

omfg absolute values! distances! totally forgot this. bloody elementary stuff. thanks for pointing me to destroyers article adam.

 
n/a

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
1st September, 2007 at 23:46:11 -

bah still doesn't work. Same problem as before. Still need a solution :S

 
n/a

Hernan



Registered
  04/03/2003
Points
  707

VIP Member
2nd September, 2007 at 06:12:31 -

Hey, Jerry, here is the easiest solution I can think of. Add these two events (or use the new OR function on the latest build of MMF2):

ENEMY alterable value A< PLAYER alterable value A + 45 + 360
ENEMY alterable value A> PLAYER alterable value A - 45 + 360
PLAYER alterable value A< 45
- ENEMY is visible

ENEMY alterable value A< PLAYER alterable value A + 45 - 360
ENEMY alterable value A> PLAYER alterable value A - 45 - 360
PLAYER alterable value A> 315
- ENEMY is visible

If you want I could add a whole mathematical story to your problem and solution, but I'll spare you that.
(Edit: fixed stupid typo)

Image Edited by the Author.

 
This space is for rent

Zi-Xiao



Registered
  29/07/2002
Points
  537

VIP Member
2nd September, 2007 at 22:52:06 -

man, my line of sight code looks klunky. THat worked thou hernan so thanks

ZI-Xiao

 
n/a
   

Post Reply



 



Advertisement

Worth A Click