The Daily Click ::. Forums ::. Klik Coding Help ::. Help, need a formula!! '(
 

Post Reply  Post Oekaki 
 

Posted By Message

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
2nd March, 2008 at 08:28:24 -

I need a formula/method that can be used to determine whether the player is in the field of view of his enemies.

It ONLY needs to handle the angles/directions of the objects, as a later process will test for obstacles.

Finding the angle to the player is also no problem.

It's literally just the forumlae/processes required.

An example to show what I mean:

Enemy faces 15°
Enemy can see 80° either side
Player is at an angle of 300° from Enemy

Player therefore *IS* within focal view

 
191 / 9999 * 7 + 191 * 7

eyeangle



Registered
  12/06/2003
Points
  1683
2nd March, 2008 at 22:37:06 -

I don't know if this is what you're after but:

Compare two general values.
Sqr((X( "Enemie" )-X( "Player" )) pow 2+(Y( "Enemie" )-Y( "Player" )) pow 2) < 300 === Make Enemie do whatever.

The 300 means that when the Enemie is within 300 pixels of the Player.

Very helpful equation.



 
theonecardgame.com

eyeangle



Registered
  12/06/2003
Points
  1683
2nd March, 2008 at 22:38:09 -

Actually on second thought, I don't think this is what you're after...

 
theonecardgame.com

»xerus



Registered
  28/06/2002
Points
  675

You've Been Circy'd!Game of the Week Winner
2nd March, 2008 at 23:19:14 -


Originally Posted by Edwin Street
I don't know if this is what you're after but:

Compare two general values.
Sqr((X( "Enemie" )-X( "Player" )) pow 2+(Y( "Enemie" )-Y( "Player" )) pow 2) < 300 === Make Enemie do whatever.

The 300 means that when the Enemie is within 300 pixels of the Player.

Very helpful equation.




Thats a good start though. I think now you can compare the angle between the player and the enemy, and you'll be set... but, thats just my theory

 
n/a

»xerus



Registered
  28/06/2002
Points
  675

You've Been Circy'd!Game of the Week Winner
2nd March, 2008 at 23:19:14 -


Originally Posted by Edwin Street
I don't know if this is what you're after but:

Compare two general values.
Sqr((X( "Enemie" )-X( "Player" )) pow 2+(Y( "Enemie" )-Y( "Player" )) pow 2) < 300 === Make Enemie do whatever.

The 300 means that when the Enemie is within 300 pixels of the Player.

Very helpful equation.




Thats a good start though. I think now you can compare the angle between the player and the enemy, and you'll be set... but, thats just my theory

 
n/a

viva/volt

Awesome Sauce

Registered
  26/08/2006
Points
  1694

Game of the Week WinnerSilverNova MemberKlikCast StarVIP Member
3rd March, 2008 at 01:17:49 -

You need that forumla to get the angle between two set's of co-ordinates... Advanced direction object? Then you can just say is that angle in the focal view range?

 
Image
http://bfollington.tumblr.com

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
3rd March, 2008 at 07:09:21 -

It's more complicated than that, cos it goes wrong when you get to the seams. It'd be easier if angles went in minus figures, but they don't. It'd be nice if they went:

0 to 180
-180 to 0

but they actually go 0-360, which makes it tough to handle when your AI is facing roughly 0° or 350°. Cos then you have to deal with the seams.

A better system would somehow convert the AI's angle to 0, and the player's angle to a different value, relative to that 0. And then convert both so they work in a -180 to 180 system not 0 to 360.

But I've managed to find an old file that handled this, and it works ok Don't know why it works, lol, but it works!

 
191 / 9999 * 7 + 191 * 7
   

Post Reply



 



Advertisement

Worth A Click