Slow mo Track to Closest

Hey guys, i’ve been busy trying to find a 2.6 Track to Closest script, wich i’ve not found yet, my question is simple -
Can someone upload a little blend with a Track to closest script? oh and also, if it’s possible can it be in slow motion? like if the object that tracked, tracks the closest object slowy
I don’t know too much about phyton right now, only importing modules, getting controllers, and that kind of stuff (the basics lol)
Any help is apreciated :slight_smile:

Guys please, i need help D:

What does it do?

Gets a list of targets in the screen? how?

targetList = [tar for tar in bge.logic.getCurrentScene() if 'enemy' in tar]

Goes through each object, gets the distance to each and compares to find the closest:


minValue = 1000
for tar in targetList:
    distanceTo = obj.getDistanceTo(tar)
    if distanceTo < minValue:
        target = tar
        minValue = distanceTo

Then you track to the object using an addObject actuator.
you set the target using:

trackAct = cont.actuators["trackTo"]
tractAct.object = target

That’s about all there is to it really.

Could you explain me how to set up the script? sorry for the dumb question, but i actually don’t understand that much about phyton :S

Stick it in the text window, should be cut and paste except for sticking “import bge” at the top.
Connect it to an always sensor, with a trackto actuator. The actuator must be named “trackTo”

It will then track to the nearest object with the property “enemy”

Simply use the S2A.closestHitObjectToObject.
The TrackTo Actuator has a delay parameter for your “slow mo” ;).

Hah, I always thought the “time” parameter determined how long the object would look at the target object. Thanks for clearing that up. (don’t know why either. probably because the “time” parameter determined how long an object lived when using the “create object” setting.)

Understandable.

The EditObjectActuator reuses the existing Time-field rather then to add a separate Time-fields for AddObject and TrackTo. This forces the tooltip to document both modes which can easily lead to confusion:

“Duration the new Object lives or the track takes”

So, it should be like this?

import bge

targetList = [tar for tar in bge.logic.getCurrentScene() if 'enemy' in tar]
minValue = 1000
for tar in targetList:
    distanceTo = obj.getDistanceTo(tar)
    if distanceTo < minValue:
        target = tar
        minValue = distanceTo
trackAct = cont.actuators["trackTo"]
tractAct.object = target 
       

And Monster, thanks, you help is apreciated :), but i can’t get it to work, so i understand this:

S2A.ClosestHitObjectToObject makes the object wich is using the module track to the closest object with certain property? (sNearTracked), what i did was that i attached the sNearTracked sensor to the phyton controller with the module S2A.ClosestHitObjectToOject and attached it to the acutator aTrackTo, is that the way of doing it?