-In the first part of this tutorial we saw how to create a Python path for a car.It was the main path.If we want the car not to collide with obstacles that are on its path we need at least an alternative one.So let's create another path.In the first case we named the coordinates as "coord1" and "orient1".We must change their names for example "coord2" and "orient2"and the name file(path1.txt).The script looks like this:
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('path1.txt','a')
sys.stdout=f
print "coord2["+str(owner.nr)+"]=["+str(pos[0])+","+str(pos[1])+","+str(pos[2])+"]"
print "orient2["+str(owner.nr)+"]=["+str(ori[0])+","+str(ori[1])+","+str(ori[2])+"]"
---We have at the moment:the car object,the circuit (no scripts,no ipo,no bricks) and two text files path.txt and path1.txt.Open a 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) coord2=range(number of data) orient1=range(number of data) orient2=range(number of data)
-number of data is the number of the coordinates we have recevied+1.At this point add the data contained in the files path.txt and path1.txt. We have the main path and the alternative one.Now we can make the car to change position if something obstacle it to go on on its path .At the end of the script type again:
if owner.hit==0: owner.setPosition([coord1[nr][0],coord1[nr][1],coord1[nr][2]]) owner.setOrientation([orient1[nr][0],orient1[nr][1],orient1[nr][2]]) if owner.hit==1: owner.setPosition([coord2[nr][0],coord2[nr][1],coord2[nr][2]]) owner.setOrientation([orient2[nr][0],orient2[nr][1],orient2[nr][2]])
Add three Int Properties named "hit" ,"value" and"nr".Add an Always Sensor-Python controller named as the script above.We need a Ray Sensor to individuate the obstacles.Put the distance and the direction(it's the running direction) attach it to Python Controller -Property Actuator.The property actuator assign to the hit-property the property value.Add another Equal-Property Sensor(hit=0)-And Controller-Property Actuator(assign to value property -1).It looks like this:

-Now if you put some obstacles on the circuit the car changes path when detects them.There's a not much accurate example Here