How to gracefully stop a track to actuator?

If I am destroying a target with my script (see below)

then when it does “end object”

anything tracking it freaks out,

is there anyway to have it smoothly return to original local rot if it’s target is gone?

also might I add, CRUSH KILL DESTROY :smiley:

I need something like if [‘Target’] ends object then return to original rot.

Attachments

RobotTracksTargets(How2handleNoTarget).blend (683 KB)

You can use a try-except clause:

try:
    actu.object = own['target']
except ValueError:
    pass # or do whatever you need to do when the 'target' object no longer exists

Cool, I just set up a “store initial local rot”

Now I can just use that to set the actuator to off, and rotate it to that location,

here is what I have so far,


import bge
cont = bge.logic.getCurrentController()
own = cont.owner
own['StartLoc']=str(own.localOrientation)
## this is ran once on each trackto object

should I have

always - python -


import bge
from bge import render
cont = bge.logic.getCurrentController()
own = cont.owner


actu = cont.actuators['TrackIt']
if own['target']!=None:
    
    actu.object = own['target']
    cont.activate(actu)


try:
    actu.object = own['target']
except ValueError:
    cont.deactivate(actu)
    own.LocalRotation=own['StoreLocal']    

here is my current setup
I am not sure why it fails, and if I deactivate a trackTo and change it’s target to “None” it still tries to track the “dead” object…

maybe I will have to have the object spawn something that it can track back to?

Attachments

RobotTracksTargets(SoFar).blend (687 KB)

You’re repeating code outside of the try-except clause. Just set the actuator’s object once inside the try statement.

if own['target'] != None:
    try:
        actu.object = own['target']
        cont.activate(actu)
    except ValueError:
        cont.deactivate(actu)
        actu.object = None
        own.LocalRotation=own['StoreLocal']

You had no else statements in the scripts only if and if and if , lol , check this one. Try to cleanup the code , cause it’s killing the cpu. If you check the performance , the logic part jumps at 20%. For a single robot scene the logic should be at 2% or less.

Attachments

RobotTracksTargetsHow2handleNoTargetFixed.blend (155 KB)

thats not the reason for the slowdown, it’s all the errors thrown and there is something else…

The logic execution was only spiking because he had an unhandled exception in a script that was run every frame, flooding the console with error messages. Other than that there are no performance issues with the code itself.

ok, I adjusted some stuff, but the brunt of the issue is tracking to a null object throwing errors,

is there any way to actually stop a trackTo ? deactivate does not seem to matter,

I think I am going to need to create a empty for each item to track to when not tracking a target,

this way there will be no error thrown, and the guns can return to a natural position,

next I need only track to if within X angle range of start…

this uses 5% max logic and could do better if I can get rid of the error and also maybe
get some python help / Don’t do thats.

Attachments

RobotTracksTargets(almost).blend (688 KB)

ok fixed it I think :smiley:

0-1% logic return
Now what is a zombie object? and do I need a shotgun?

End ObjectDestroy the current object (Note, debug properties will display error Zombie Object in console)
why?

now I get a game crash if I uncheck debug property health… and the “player” dies…

Attachments

RobotTracksTargets(Works).blend (691 KB)

EDIT: Never mind, you fixed it yourself. I hadn’t read your new post before posting.

now I get a game crash if I uncheck debug property health… and the “player” dies… - this is odd?

How about this AutoTurret example , looks more simple and only one script.

Attachments

AutoTurret 001.blend (86.9 KB)

The game I am making is using modular robotics, that don’t know anything about each other,

So I can rip robot A’s arm off and stick it to Robot B, and it will work

Ok, so using a empty as a target could work, if I could find out if it’s linked to the object somehow.

Alright, so now, I need 1 empty spawned 1 time, for each track to item, that automagically parents to the “torso” (I think?)

so when the track to is finished, each item begins tracking it’s empty, and then shuts of the actuator, and when the limb is removed, the empty is ended.

Sounds good. You can use empty.setParent(target,true,true) and empty.removeParent() but you could also do empty.worldPosition = target.worldPosition to stick the empty onto the target.

like always use the same empty and move it to the enemy, and once dispensed move the empty back to the “start” local position.

that makes sense as the empty is required anyway, and storing a vector as a property is easy enough.

So always track to empty, with weapons etc. and if head sensor finds target move empty to target…

that will require a little re-write… just feeding the target data to each empty, and having the guns track them…

then I don’t need to keep changing track to targets.