Trouble with "Clones"

For a school project due in the spring I am making a video game. I know very little in python (Only up to unit 6 in the tutorial for 3.3.2) but I know quite a bit in the blender game engine. As part of a main mechanic, I am trying to make a character track to a specific object. I am unsure how to do this . My first thought was to make a base mesh and have it track to spawned “Clones” that appear when the game starts, or when I press a button. But instead they track to the base object in a hidden layer. I tried linking an object from another scene, same thing. I tried making poles appear for the character to track to those instead by the press of a button when in game courser was over any spot after “selecting” a character. It worked and they appeared. but again it tracked to the object in the hidden layer. I tried using property specific actions for the interactions between the poles and characters, but it didn’t work. I didn’t know if anyone knows a solution, or has any ideas that would help. Thanks.

I assume you’re using the Edit Object actuator in Track To mode. In order to track objects that are added during runtime, you have to update the actuator’s object property with the newly added object.

import bge

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

# add new object
newObj = scene.addObject('ObjectName', own)

# update actuator
track = own.actuators['Track']
track.object = newObj

My first thought was to make a base mesh and have it track to spawned “Clones” that appear when the game starts, or when I press a button.

So what are you trying to achieve with these objects that you track to seems like you’re adding them to turn the character?

You are correct in assuming that I am using Edit Object actuator in Track To mode. I thank you for supplying me with a code, but as I stated I know very little about python and nothing about how it works with blender. If you can show me, or direct me to a place to show me how exactly the code works that would be well appreciated thank you.

Kheetor, Kind of. My whole goal is to spawn in a person to go collect resources. As I have only ever used logic bricks, I decided to try to use a track to constraint to get a single character of multiple to go to a specific object. I ran into the problem of; if there are multiple objects on screen, I can’t exactly have logic bricks for ALL of those objects, and re-do it between scenes/levels. So I decided to have a character track to a single object and have it track to a single one. But before I could work on individual selection, I discovered this other problem.

This kind of dynamic logic requires Python.

Please have a look at The trackTo actuator and object instances. It describes the problem and offers some solutions. I think you will see why a logic-brick-only solution would not be sufficient.

Edit:
Nevertheless I think you discovered a workaround to track a single object only and let this object move to the desired locations. This should work with previously known locations.

Ok, let’s talk about what you want to make ultimately instead of what little bit you are going for at this phase?

So if I understood correctly you have multiple objects and multiple characters. The characters need to go to (nearest) objects? Or each character needs to go to one specific object?

You are probably “cloning” the objects via Add Object in-game rather than duplicating objects in editor. That means they will all have the same name and identifying between them will be impossible based on the name alone. You probably need a property “id” or something to keep track which is which. Unfortunately I can’t help you so much with logic setups to do that.

EDIT: And Monster has this thing solved with illustrated tutorial 3 years ago :slight_smile: He is awesome.

Thank You all very much. Monster has confirmed my theories (Thank you) I now just need to take the time to finish learning python and learn how to apply it to Blender, as I suspected I would have to. I also have already come to the conclusion as well that there is as of yet no logic brick solution, because it tracks to the specific object rather than the “clones” because it probably had a different ID to it… And to answer Keetor’s Question, My ultimate goal is to have a “Unit” based RTS game that requires the player to grow his/her base by building buildings using materials and resources (thus the requirement for unit selection and tracking to an object) as well as using other units to fight off enemy hoards… with the same base building in realtime. Kind of a RTS/Survival game.

go go go !


Track to closest?

Attachments

TrackToClosest.blend (435 KB)

Not exactly track to closest, because the player may want to send off his troops to the other side of the map. Although I am sure this might come in handy. Thanks

I am sorry I never followed up on this, But I have successfully accomplished my goal of getting my character to track to a “clone” from a hidden layer. I want to thank Monster very much for their help. I have read through their Python tutorial and I am now successfully writing codes. And thank you to the rest of you for your help too. I will be starting a new thread just for my game. I will post it in here when I start that up. Thank you.