1
$\begingroup$

I wrote a script to change an Edit Object actuator track object based on which object it is near.

Here is the script, pretty much straight off the template:

import bge

def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner

    sens = cont.sensors['NearBad']
    actu = cont.actuators['Attack']

    if sens.positive:
        actu.track_object = sens.hitObject
        cont.activate(actu)

    else:
        cont.deactivate(actu)

main()

The actu.track_object = sens.hitObject is the line in question.
I wrote that based on what I think it should be, but what is the right syntax? How do I really do that?

Disclaimer: Although I work with BGE all the time, I have no coding experience at all.

$\endgroup$

1 Answer 1

1
$\begingroup$

Edit Object Actuator

The way you change an Edit Object actuator's object to track is with object.
Here is what the if statement section of your code looks like.

if sens.positive:
    actu.object = sens.hitObject
    cont.activate(actu)

Steering Actuator

The way you change the Steering Actuator's object to track is with target.
Here is what the if statement section of your code looks like.

if sens.positive:
    actu.target = sens.hitObject
    cont.activate(actu)

I initially thought you were using a different actuator (Steering) that is why both methods are listed.

$\endgroup$

You must log in to answer this question.

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