Tracking to an Added Object from a Hidden Layer

It took me a few minutes to figure out what was going on but it seems very straightforward now. I just don’t know how to remedy the issue.

The user controlled player is able to throw ‘diversion’ objects to draw enemies away. When the object hits the ground it will make a noise and the enemy will change to track to and move towards this new object, until the user player begins moving again.

The issue that I am having here is that when the enemy is activated to track to the diversion, the enemy will only walk towards the unmoving location in which the object is hidden in the other layer. I’m using the ‘add object’ actuator to bring it into the active layer, but the enemy will never track to the visible and dynamic object that I create within gameplay.

Is there any simple way to resolve this? I can understand why it would do this but it is really interfering with my intentions.

Thanks.

You could use python?? Do you know python?

I know OF python. I realized that may be the only way around the issue. I guess now’s as good a time as any to look into learning some.

If anyone had a really basic blend file with an example of what I’d need to do I find I learn much better deconstructing hands-on.

Ill make you a blend file. Do you know about states? what your doing may involve them. They probably wont be in the blend I give you…but for your purpose it might be smart.

Yes, I think I understand the basics. I’ve used states in some of my logic bricks too. Thanks.

Ok. So I made one attempt and it failed…:o
I realized that this is not as simple as I thought it would be. The track to actuator can only do so much…I have another idea and its way better than the first one, unfortunately its also more complicated…:frowning: If you want, you can upload your file that you need this in, and with your guidance I can implement it directly into that. That way you dont have to do it your self and its alot easier on the both of us.

Here is the failed file: Example_Enemy Distract.blend (290 KB)

Well, if you can please send me your reply and if you feel comfortable your files. :smiley: see you tomorrow.

Sunjay03.

PS. I would do the work right now…but I have home work…:(:frowning:

Nothing about this requires states… it’s basic Python.

Basically, all of the created objects have the same name as the “Base” object (the unmoving object in the other layer). However, the actual added instance is inaccessible without Python.

You can either use the instantAddObject() method of the addObject actuator to get a reference to the last created object, or you can use the scene’s object list and look for the object you want.

I made an example that does this… but note that it’s probably not the best solution. It’ll WORK, but if your scene gets too big, it has a possibility of being slow.

Use the arrow keys to move and the space key to place a distractor. The distractor dies after a set amount of time, or when the enemy gets close to it.

A better solution might implement a list of added objects instead of having to go through the entire scene to check for what we want.

-Sam

Attachments

trackToDistractor.blend (61.3 KB)

Great! I copied the script you put in there and made the necessary modifications and it works exactly how I wanted it to now. I’m looking at the python and while I don’t understand all of the commands being used, I think I do understand what is happening for the most part.

I do have a question about the obj.name == “OBdistract” part. Are all the added distraction objects given this name? The original object I noticed is just called ‘distract’. Is the ‘OB’ something that is added to objects that are added using the edit object actuator?

Thanks again Sam for the simple solution. I’m hoping that from here I might tinker with that basic script to try to understand it better. If things do start getting slow I’ll have to try implementing the list of added objects but for now this will do the trick.

Sunjay, thanks for your work too. Looks like this issue is solved.

You are right, the names of the KX_GameObjects are “OB”+name. So you have to be careful with names. They appear different to that what Blender tells on the GUI. For example the name of default Cube is “OBCube” in BGE, while Blender tells you it’s name is “Cube”.

just for info