Hi,
well, i suppose you use the veicle wrapper constraint, downloaded from tutorialsforblender3d.com (great site), right?
so, the first thing to do , is separate the code of imput (keyboard pressed) to the code of the constraints setup(powertrain.py)
do a new script , (imput.py)
where you pass the values of the keyboard , to a property .
example:
#imput.py
if sensors["Gas"].positive:
own["Gas"] = True
else:
own["Gas"] = False
then modificate , powertrain.py… from this:
#powertrain.py
if sensors["Gas"].positive:
setconstraint..
to this:
#powertrain.py
own = controller.owner
if own["Gas"] == True:
setconstraint..
so, powertrain is not more dependend from the keyboard , but from the property
these properties can be written or from the player or from the AI
while powertrain.py react to these property exactly in the same way
2 worlds about the AI .
the AI need to have a target (or a point 3d)
and calculate where it is , forward/back,left/right
you can get this info using this function:
distance, vec, vec_loc = own.getVectTo(target)
#the matter is the last
x,y,z = vec_loc
if x < 0 ... target is at left
if x > 0 ... target is at right
if y > 0 ... target if forward
if y < 0 ... target if back
based on that , write the property that then are readed in powertrain.py
choose what seem better :
own[“steer”] = “left”
or:
own[“imput_x”] = -1
a number is more flexible but also less readable
in all case , the property written from the player must be exactly the same that write the AI
so, start before to write the player , then do the AI