2d AI

Hey.

I am making a ragdoll fighting game in 2d.
But i have no idea how to make Ai.
Aint there a code that says: go to possion head.x head.y head.z in speed: ?
Please help:evilgrin:
PS. the game can be found here: http://www.theultimate.hostingf.info

what exactly is the intent in this code?

go to possion head.x head.y head.z in speed:
if you mean you want an object to move towards the head at a certain speed, I believe you’d need to get the vector towards it (head.position-own.position)
normalize it (divide X,Y,and Z amounts by the vector’s total length, I believe)
then multiply by the speed you want. you can then add this to the object’s current position, or set it in a motion actuator.

pseudo-code to do this (untested)- all the places where there are 5 spaces should be replaced with [tab] (can’t put tabs in this forum)


g=GameLogic
c=g.getCurrentController()
o=c.getOwner()
from math import sqrt

#function calls
def pythag(A):
     return sqrt(A[0]*A[0]+A[1]*A[1]+A[2]*A[2])
def normalize(A):
     B=pythag(A)
     return [A[0]/B,A[1]/B,A[2]/B]
#get head's object index
oblist=c.getCurrentScene().getObjectList()#not sure if it should be g.get... or c.get... in the beginning of this line
head=oblist["OBhead"]#replace OBhead with the name of the head object plus OB at the beginning. this must be spelled exactly correct, including caps

speed=1#change this value

headPos=head.getPosition()
oPos=o.getPosition()
moveVec=[headPos[0]-oPos[0],headPos[1]-oPos[1],headPos[2]-oPos[2]]
moveVec=normalize(moveVec)
moveX=moveVec[0]*speed
moveY=moveVec[1]*speed
moveZ=moveVec[2]*speed

#add to position
o.setPosition([oPos[0]+moveX,oPos[1]+moveY,oPos[2]+moveZ])

I have a feeling this is more complex than it needs to be, but I tend to overthink things, and I don’t have blender in front of me…

Thanks:D

I´ll try it out:D

Cant get it work:S
Can you please make an example?:o

there were a couple small bugs in the script- the version in this blend file still has some problems (the physics engine won’t like it very much, and there’s trouble with vectors that have zeros in them- but it works, and I’m too lazy to fix the problems right now. at least it gives you a place to start.)

There is only one problem.
It goes into to the head. So the head is inside the other head.
If you can fix that its just what i want:)
Hope you will help me, when you have time:)

hum… shouldnt it be easier to use the track to actuator and use the motion actuator putted to Local go into Y force?

the problem with the track to actuator is that it rotates the object in question, whereas my method allows it to face any direction. that said, if you don’t care about hte rotation, use the track to actuator instead. it’s better ^^

yeah but you could use an empty that track to but you VERTEX parent the object to the empty,
so when tracking the empty rotate but not the object,

while that would work, a single script is probably neater and faster.
wait, can you vertex parent to an empty? they don’t have vertexes…

Someone there now a better way?
I have try’d that track to thing. But it dos’nt work good.