0
$\begingroup$

I make a game with the Blender Game Engine. I would like to make a cube (Enemy) which moves inside a navigation mesh. This cube should follow all the objects with a specific property. The cube also should follow the nearest of this objects in the navmesh. I found this script. But it only work for the "Edit Object" actuator. I need this script work for the "Steering" actuator and the path following. I hope you can help me.

def target_prop(cont):
self = cont.owner
objects = self.scene.objects

test = [o for o in objects if self["Cube"] in o]
test.sort(key=lambda o: self.getDistanceTo(o))

target, *_ = test

act_track, *_ = cont.actuators
act_track.object = target

for act in cont.actuators:
    cont.activate(act)
$\endgroup$

1 Answer 1

1
$\begingroup$

Simple change. The syntax for the "Steering" actuator calls for a target field, not a track _object field. So your new snippet looks like this:

def target_prop(cont):
self = cont.owner
objects = self.scene.objects

test = [o for o in objects if self["Cube"] in o]
test.sort(key=lambda o: self.getDistanceTo(o))

target, *_ = test

act_track, *_ = cont.actuators
act_track.target = target

for act in cont.actuators:
     cont.activate(act)

you can see the only change is line #11

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .