-This tutorial show how a car that have a predetermined path on a circuit will avoid obstacles placed on its path . The first thing we need is to create a main path for the car.Open Blender model a car and circuit.All that we need is a number of cooordinates that can use further with owner.setPosition( ) .I think nobody intends to put manually a list of numbers to create a path,so let's use something else.The easiest way to create a path in Blender GameEngine is to use IPO curves.Open IPO window (Shift+F6) .Move your car on the circuit putting IPO keys where you want.This will be the main path.Now let's translate this motion in a list of coordinates.Open Text window(Shift+F11) and type the following script:
import GameLogic
import sys
contr=GameLogic.getCurrentController()
owner=contr.getOwner()
owner.nr=owner.nr + 1
pos=owner.getPosition()
ori=owner.getOrientation()
pos[0]=round(pos[0],3)
pos[1]=round(pos[1],3)
pos[2]=round(pos[2],3)
f=open('path.txt','a')
sys.stdout=f
print "coord1["+str(owner.nr)+"]=["+str(pos[0])+","+str(pos[1])+","+str(pos[2])+"]"
print "orient1["+str(owner.nr)+"]=["+str(ori[0])+","+str(ori[1])+","+str(ori[2])+"]"
-Press F8 to see the Realtime buttons.Add an Always Sensor connected to Python Controller named as the script above.Give a frequency of pulses to the Sensor.It will depend by number of data anyone want to receive.(lower the number of pulses greater the number of data) .Add another Always Sensor -And Controller-IPO actuator.The IPO Actuator will contain the number of frames you created above for the path.Add an Int Property named "nr". The logicbricks will look like this:

-Now press P-key with the mouse over the 3D window and wait your car to complete all the frames of the path. Then press immediately Esc.Now open your Blender folder and will note a file named "path.txt" in it.It contains the list of the coordinates of the path and orientation of the car.(At the end of this file maybe some data are repeated.It's because the car before pressing ESC stays at the end of path and Always Sensor go on pulsing.) Try to find and to cancel this data.Now return to Blender.Cancel The IPO curve ,the logicbricks and the above script.Open a new Text window and type:
import GameLogic import math contr=GameLogic.getCurrentController() owner=contr.getOwner() owner.nr=owner.nr+1 nr=owner.nr
coord1=range(number of data)
orient1=range(number of data)
where number of data is the number of coordinates we received, plus one. Now we have to add the data of the file "path.txt".How to do it? Open another Text window .Press Alt-Shift-F and confirm Open.Choose the file "path.txt" and press Enter.Press Alt-a to select it all and then Alt+c to copy.Go to the text window w were writing the above script put the cursor at the end and press Alt+v.Put the cursor at the end again an type:
owner.setPosition([coord[nr][0],coord[nr][1],coord[nr][2]]) owner.setOrientation([orient[nr][0],orient[nr][1],orient[nr][2]])
-Press F8 for Realtime Buttons and add an Always Sensor-Python Controller named as the script above.Add an Int Property named "nr".Press P with the cursor over the 3D window and voila ,the car will do the same path you did with the IPO curve.Changing the pulse frequency can be changed the velocity of the car.
-Now let's go to thesecond part to see how to avoid obstacles.