That’s really nice! I’ve always liked this kind of games. I remember that I tried to do a similar game to this when I was learning Blender (still does:D).
Anyway, I read on your “Tracks … ?” thread from “Game Engine Support and Discussion” that you doesn’t want to learn python, but still wanted to add AI to this game. I don’t know if you already knows a way to do this, sure you can use ipo’s but the car that you are driving would just stop if you crasches into it. Therefore I decided to share two codes and a tutorial how to add it (the code isn’t written by me from scratch, but unfortunaly, I can’t remember who did this first). Anyway, it’s quite easy to setup.
To start with, add some empties and place them around the track. You can name them anything you want to, but if you doesn’t name them the same way as I, you will have to change the names in the codes too. I’ve named them:
and so on as many as you need. Those are the objects that the AI will follow. But you’ll also need one named:
Here, the vehicle will restart after a lap. But you will also need one named:
this one will only controll the car.
Now what you need to do is to select your “gameData_ob” and do following:
Add one “Always” sensor and one “Python” controller. Add one new code and paste in this code there
GameLogic.pathForw1 = ['pathNode_ob', 'pathNode_ob.001', 'pathNode_ob.002', 'pathNode_ob.003']
Note: If you used more empties, which I guess that you have too, you will have to add their names just as I did.
Note2: It will go to the next empty in the list, so write them in the same order as they are in the track.
Now select the AI car, add a new text and paste in this
# get the controller the script it attached to
controller = GameLogic.getCurrentController()
own = controller.owner #get owner
# get a list of actuators connected to the python controller
actList = controller.actuators
nextNode = own["nextnode"]
#get nodepath to follow
pathchoice = own["pathtofollow"]
glVar = ("GameLogic." + pathchoice)
path = eval(glVar)
#collect nodelist from global variable
track = actList["targetnode"]
travel = actList["movetonode"]
#Check distance from targetnode. switch to next if close enough
targEmpty = path[nextNode]
pathlength = len(path)
distance = own.getDistanceTo(targEmpty)
if distance < 9.0:
nextNode += 1
if nextNode == pathlength: #At end of path, respawn at spawnpoint
nextNode = 0
scene = GameLogic.getCurrentScene() #Get the scene
respawn = own["respawnpoint"]
spawnpoint = scene.objects[respawn] #Get spawnpoint_ob and get xyz
spXYZ = spawnpoint.position
own.setPosition([spXYZ, spXYZ, spXYZ])
track.object = path[nextNode]
#set proprty to new value
own["nextnode"] = nextNode
speed = own["travelspeed"]
spdXYZ = [ 0.0, speed, 0.0]
travel.dLoc = spdXYZ
Now, setup the properties and logicbrick just as I did.
Note: The name off the properties and logicbricks has to be exactly the same as in the attached picture.
Now it should work, only hopes that this will work for you, and that you still are using 2.49, otherwise these codes wont work. Also hopes that this will come in use for you.
Last note: If you want the car to drift just as the car you are driving, just change the property “travelspeed” to 0.000 and hook up this Always -> And -> Motion, and in the motion, change so that it’s the same as the trottle in your car.
Also, in the “Track to” actuator, it stands “pathNode_ob.001”