I want to make a tank patrol between two empties (E1 and E2)
When it is close to E1, it should turn towards E2 and vice versa.
It can be done with TrackTo and States I guess, but I prefer to
keep the AI within Python, for various reasons (mainly because if
I want to patrol between 3, 4, 5 points, logic states will become really messy)
I suppose I need to subtract the two positions, then convert the resulting
vector to an orientation ? Something like that, but Im not sure.
Could somebody help ?
yes but with Python you can create one AI and then give the empties as arguments.
Plus you can change the patrol points at runtime.
With logic bricks, for each patrol combination I need to write the whole logic from scratch.
For a single level, I would end up with tens of different scripts.
I assume you can not change the TrackTo target from Python, right ?
Be careful with alignAxisToVect () there’s a bug which causes flipping of the z axis sometimes when tracking on the y axis. Your tank can end up upside down!
also, I have notices using Local is more effective
local = target.worldPosition-own.worldPosition
local = target.wordOrientation.inverted()*local
if local.x>0:
#object is in front of you
if local.y>.1:
#(object is on left)
elif local.y<-.1:
#(object is on right)
else:
#object is in front