The Daily Click ::. Forums ::. Klik Coding Help ::. Look at me!
 

Post Reply  Post Oekaki 
 

Posted By Message

Deleted User
4th January, 2009 at 20:46:26 -

I want some of he AI to look directly at the player, but just like how I have the player set up, I don't want the AI to just change direction, I want them to swing that direction. I obviously do that by setting the direction number to go to, then add or subtract 1 until the AI hits that direction then stop. The only problem I have is calculating that direction. The detection I'm using is a mathematical circle that sits around the AI, so when the player is within say 100 pixels of the AI, the AI swings around to that direction, so it most likely going to need some kind of formula to determin what angle the character is entering from.

 

Deleted User
4th January, 2009 at 20:46:55 -

Sorry, I explained this like a retard, I've been up for 2 days working on this.

 

easyname



Registered
  15/04/2008
Points
  450
5th January, 2009 at 07:35:25 -

Program?

MMF2 has a very useful object for working out things like this called the advanced direction object

 
n/a

chrilley

Insane Beaver

Registered
  05/01/2002
Points
  704

Game of the Week WinnerVIP Member360 Owner
5th January, 2009 at 09:53:01 -

I think TGF/CNC and MMF1/MMF1.5 also have it.

 
Image

traugott.simon



Registered
  23/08/2008
Points
  91
5th January, 2009 at 12:13:42 -

if you dont want to use an object try this:

create an invisible detector with full 32 directions for each enemy and make it follow it (only possible via fastloop).
Make it aim in the players direction all the time and by the time you want your enemy swing around just subtract 1 of the direction until the same value of the detector is reached.
I guess this is far to complicated if the object can do the same but it is possible

If you dont want to have a hundred enemys on screen at the same time, the detectors wont leed to a lag.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
5th January, 2009 at 14:15:30 -

Advanced Direction extension is the easy way. The pure maths way looks something like this:


Object1 = Enemy Object (the one doing the searching)
Object2 = Player Object (the target)
Angle1 = Current angle
Angle2 = Angle to target object
RotateDir = Angle to target object, in range -180 to 180 (ie. degrees clockwise/anticlockwise)
RotateSpeed = Degrees to rotate per frame


Always:
Set Angle2 to: ATan2( Y("Object2")-Y("Object1"), X("Object1")-X("Object2"))

Always:
Set RotateDir to: ((Angle1 - Angle2 + 540) mod 360) - 180

if RotateDir < RotateSpeed:
Set Angle1 to: Angle1 + RotateSpeed

if RotateDir > 0 - RotateSpeed:
Set Angle1 to: Angle1 - RotateSpeed

Edited by Sketchy

 
n/a

Deleted User
5th January, 2009 at 18:55:14 -

I tried that, and I also stumbled upon the direction calculator which worked in one line of code. Which one is overall alot better and is most likely not going to cause as much problems in the future?

 

easyname



Registered
  15/04/2008
Points
  450
5th January, 2009 at 19:42:02 -

If it works, then use it

However, the advanced direction extension has more features (I think?)

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
5th January, 2009 at 19:43:02 -

It's better use an extension for this - it's easier and faster (in terms of not lowering the games framerate).

The big downside to it, is that the rotation must be a whole number. Occassionally you'll find that you need more precise control, and then you'll have to do it the hard way.

I don't remember exactly what the Direction Calculator does, and I only have my laptop at the moment, so I can't check. If it *can* handle floats and works for duplicates, then it's probably the way to go.

Incidentally, the complicated way I suggested still needs a line or two to be perfect - at the moment, the margin of error is equal to RotateSpeed.

 
n/a

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
5th January, 2009 at 22:52:02 -

I suppose another possible solution would've been having an invisible clone of your object and having it constantly look towards whatever you want. Then when the time comes, do something like:
Dir("Original") < Dir("Clone") -> add/subtract 1 to Dir("Original")

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445
   

Post Reply



 



Advertisement

Worth A Click