Hi, I’m new to python and attempting to adapt a script for my own use. I’m struggling with a 2 problems.
First, i am trying to set a tracking time but this seems to break my script and cause it to do nothing.
Second, i want the object to pick a target randomly from a list but it constantly selects a new target.
The code is below and i have attached a demo of what I’m doing.
Many thanks, Mike
import bge import random def main(): cont = bge.logic.getCurrentController() own = cont.owner near = cont.sensors['CLOSE'] see = cont.sensors['VISION'] hear = cont.sensors['HEARING'] walls = cont.sensors['WallSearch'] act = cont.actuators['tracker'] targetNEAR = near.hitObjectList targetSEE = see.hitObjectList targetHEAR = hear.hitObjectList if see.positive and walls.positive: target = random.choice(targetSEE) act.object = target # act.setTime(10) cont.activate(act) elif near.positive and walls.positive: target = random.choice(targetNEAR) act.object = target # act.setTime(10) cont.activate(act) elif hear.positive: target = random.choice(targetHEAR) act.object = target # act.setTime(100) cont.activate(act) else: cont.deactivate(act) main()
HELPME.blend (404 KB)