Targeting reticule theory.

I’m experimenting with a targeting system for a space combat-esq game.

I would like each enemy to have its own target box.

My initial thinking was to have, for every enemy, a target box in an overlay scene that uses get/set position to stick with to the appropriate enemy.
This I have done with one enemy fairly easily.

However it is fairly obvious that if I have lots of enemies then I run into some problems.

First off is I don’t want to have lot of get/set position scripts running, what I think would be better, but i am unsure on how, is to have one get position script, that all enemies use that generates a position variable based on the enemy object name. << not sure if thats possible but seems to be a logical way to do it.

I guess a better way to put it is, is there a good way of managing lots of get/set positions in one script?

Is this even a good way to manage the targeting system?

Thanks for any help.

The problem with using object names is that they aren’t changed when an object is added. That is to say, if you add a whole bunch of objects called “Thingus”, then the engine reads a whole bunch of objects called “Thingus” and not Thingus.027 or whatever.

What this means is that, when you tell the system to lock onto the object with name Thingus, it defaults to the first object created with that name. Therefore all targets will stick to the first ship created.

The only thing I can think of right now is to parent a seperate target to each ship and then link a visibility brick on the target to the Python bricks of the ship. But that would probably be messy.

i made this thing with setRot.
in main scene i made an empty located exactly same place as camera tracking to target. in seperate (overlay) scene camera must copy rotation and position of camera in main scene. There an empty copying location of camera and copying rotation of main scene empty. finally parent an image to this empty.

if you have many enemies… easyer would be switching from one to another.

Thanks for the replies.

Cool looking game martinish by the way.

Ive managed to get that far my self, ill take your advice though for the time being and switch between enemies and use the radar for keeping track of the others.

Id still be interested if anyone knows a good way to get/set position of a more than one object using one script.

Just an idea:
You could add a list of objects to GameLogic at startup (e.g. GameLogic.enemyList). With a loop you can go through all objects present in the scene. Add the objects with property “enemy” or whatever to the list.
In another script you can access the objects just from the list (e.g.GameLogic.enemyList[ number ].getPosition()).


Thanks again Monster, thats what I was looking for!

Another question…

for i in range(0,len(objList)):
    obj = objList[i]
    if hasattr(obj,"enemy"):
        if own.getDistanceTo(obj) &lt;100:
            enemyList.append(obj) = enemyList[own.targetnum].getPosition()

own.enemycount = enemyList.count(obj)

I’m using this code to help cycle through targets that are in range. (By adding or subtracting “targetnum”
However I need to know many objects are in range so i can cycle from the last to the first enemy.

However count(obj) returns only 0.

Am I going about this the right way?
Thanks for any help.

Wouldn’t len(enemyList) do what you want. You already used it in the second line with len(objList).

Just to expand slightly, as Monster says, len() is probably what your after as enemyList.count(obj) will return the number of times the object ‘obj’ appears in the list.


Thanks (again!), id tried len() before but Ive now realized it didn’t work because i added a property to the wrong object.