I’ve come unstuck doing a little test. I decided to brush up my Python skills by emulating the track to Actuator. How hard can it be methinks, especially as I’m only doing the X, Y tracking. How wrong could I be. Been messing with this for ages, note it works as i wish in the positive X direction but behaviours messed going the other way.
oblist = GameLogic.getCurrentScene().getObjectList()
bot = oblist['OBenemy']
player = oblist['OBplayer']
axis = '-y'
if axis[-1:]=='x': dir = 0
elif axis[-1:]=='y': dir = 1
elif axis[-1:]=='z': dir = 2
#find difference in location
dloc = bot.getVectTo(player.getPosition())[1] #not 0, and not 2. I don't know what 0 and 2 are, but [1] is the location difference.
#convert all of the numbers in dloc to - numbers
if axis[:1] == '-':
temp = []
for data in dloc:
temp.append(-data)
#end for
dloc = temp
#end if
#0 = no turning, 1 = instant turn
rotspeed = 0.1
#now apply the variables to the magic command
bot.alignAxisToVect(dloc,dir,rotspeed)
#to keep the z axis straight up, align it to world z axis
bot.alignAxisToVect([0,0,1],2,1)
That can be changed and simplified in most situations, but you can probably adapt that to what you want.
if you want to make a runtime out of your game, and the user shouldn’t have to install Python, than I woudn’t use “import math”.
Currently I’m freeing all my code from “math” including an a* pathfinding.
“Almosts” solution looks better, because there is no usage of “math”.