0
$\begingroup$

If I set up two empties that can add specific new objects to the game every second, can the objects added by the first empty track the location of the objects added by the second empty?

If this can be done in Python, that would be awesome! Thanks guys for the help!

$\endgroup$
1
$\begingroup$

Rather than put the code in here, I'm providing the file. It's a little more hackish than I'd have preferred, but you can see how it works and clean it up if you wish.

It works with 3 objects: Scene Master, Enemy Generator and Bullet Generator. In an inactive scene I created an Enemy object and a Bullet object.

The Scene Master runs the script, which gets the generators, enemy base and bullet base. Every 180 seconds it adds an Enemy at the Enemy Generator position and a Bullet at the Bullet Generator position.

Enemies have a constant speed along the Y axis. Bullets have an unset Steering actuator with a constant speed roughly matching the corresponding Enemy. The Scene Master sets the new Bullet's steering target to the new Enemy. The Bullet then actuates its steering logic and starts chasing its corresponding Enemy.

Something I want to impress upon is that you can't target copies of objects by name. Each time you add a new Bullet or a new Enemy they'll all have the same name (Bullet or Enemy). So when we add the objects to the scene we do it while at the same time equating it to an object. This adds the object to the scene and creates a data object corresponding to the newly added version. This data object can be saved in a scene object's properties and accessed later, even if you add 3000 new versions of the same object.

http://dan.gslyr.com/blender/steering.blend

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Thanks! The blend file really helped, all i needed to do was adapt it to cross over multiple scenes, but thanks for all your help! :D $\endgroup$ – christai Jul 6 '15 at 22:57
0
$\begingroup$

You might try giving each added object a new property. Such as Alpha and Omega. Each added Alpha object would look like Alpha=1, Alpha=2, etc. And so forth with Omega. In your Python set the target in your tracking actuator to the coinciding object.

So if you add two objects, one with Alpha=1 and the other with Omega=1, set the target for Alpha's tracking actuator to any object with Omega=1.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Can this be done accross multiple scenes, such as a main game scene and a heads up display scene? $\endgroup$ – christai Jul 2 '15 at 23:10
  • $\begingroup$ "set the target for Alpha's tracking actuator to any object with Omega=1." Im curious as to how that would be accomplished, the rest is elementary, but how to set the target of an actuator by the the property of another object? $\endgroup$ – Scalia Jul 2 '15 at 23:19
  • $\begingroup$ @Radish Keep a global list of all Alpha's and Omega's. Each time you add them add them to a list. Then when you want the Omega object with Omega=1, iterate the list til you find it. $\endgroup$ – Daniel Jul 2 '15 at 23:22
  • $\begingroup$ I'm confused... The object that does the tracking searches the entire list each tic? This sounds like it could slow a game significantly if there are may objects with the Omega property. $\endgroup$ – Scalia Jul 2 '15 at 23:24
  • $\begingroup$ @Christai This should help you. blenderartists.org/forum/… $\endgroup$ – Daniel Jul 2 '15 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.