Track-to issue...

Alright, I’ve changed gears in one of my old projects and have struck a problem…
Effectively, I want to add an object and have another object track to this newly added object, but when the latter object starts tracking to the former, it tracks to where the object is on the “hidden” layer instead of the present layer…
This shouldn’t be possible should it?
I’m thinking if I can figure a way to end the original object when its newer counterpart is added, all should work, but all my workarounds have so far failed, resulting only in the new object being destroyed instead or just nothing happening at all… :spin:
Here’s the file minus my attempted workarounds:

Attachments

shooter2.blend (139 KB)

You’ll definitely have to use python for this. You have to dynamically set the object to track to after you created it.

A script looks for the new object’s name and passes it to the object actuator so it tracks to the new object instead of Cube.001

I’m too busy right now to find or create the script for you but it can easily be done with 10 lines of code.
All I can tell you is that the Add Object actuator has a variable that holds the name of the last object created.

Put this code in the “Text” where you wrote your message, then get rid of addObject actuator.
Change the controller that the space bar sensor is connected to into a python controller.
Type “Text” into it. See image on the bottom.


cont  = GameLogic.getCurrentController()
own   = cont.owner #The object that the script is running on.
scene = GameLogic.getCurrentScene()

blueCube    = scene.objects['OBCube.002']  #Need to get the blue cube.
addedObject = scene.addObject("Cube.001",own)  #A scripting way to add 
                                                #objects without the actuator.

blueCube.actuators['act1'].setObject(addedObject)  #Get the trackTo actuator
                                                    #and set it to the spawned object.

Hope that was helpful. See if you can figure out what the script is doing.

Attachments


Sweetness, thanks!
@Djordhan: Thanks for clearing that up…
@Littlebob: Thanks for the script; I’ll tweak it a bit later, but for now it does what I want. :stuck_out_tongue: