Problem with AI

Hi everyone, #BlenderDude here! Just got a question about AI…

I have made basic AI that works great with logic bricks, but I have a problem. In my game I want levels, so I’ve created a empty that adds my character from another layer, to the main layer. But now my AI wolves are going to the position of the character in the other layer and not to the added character in the main layer!

Hope this isn’t to confusing…

If you can help please leave a comment. Thanks, #BlenderDude.

dont know how to fix that, but why not always have the player in the main layer?

you could add the terrain and stuff from other levels from the hidden layer to the main layer with the player

Dynamically created objects require dynamically adjusted trackTo-targets.

In general, you need to ask yourself if the design still fits your needs.

previous design:

There is one character which is known at design time (Before you start the BGE). You have many wolves that know that character at design time.

current design:

There is one inactive character that is known at design time. You have many wolves that know that character at design time.
During the game you add new characters.

What you want:
There is one inactive character that is known at design time. You have many wolves that know that character at design time.
During the game you add new characters. -> The wolves should know the added character(s).

This leaves some questions:
When?
Which one of the characters? Remember you have at least two characters, an inactive one and a added one. With each add you get one character more. With each endObject you have one character less.

(Yes, due to the dynamic nature you need Python. Before posting any code I would like to see the answers to the above questions as they are essential to design the code.)

Thanks everybody! Do you maybe know of some other way to make levels?

Thanks for that idea!

You need a script where they will track to the property instead of to the player.
So {Near-Sensor}Near >>>Python{TrackToNearestProperty.Py}>>>{Edit Object-TrackTo}Track
This Script ought to help you.


from bge import logic

#import standard stuff
cont = logic.getCurrentController()
own = cont.owner

#import the sensors and actuators
Near = cont.sensors[‘Near’]
Track = cont.actuators[‘Track’]

if Near.positive:
# get a list of objects that have been hit by the near sensor
hitObjs = Near.hitObjectList
dist = 0
obj = None

# Iterate over the list to find the closest object
for item in hitObjs:
    if item.getDistanceTo(own) < dist or dist == 0:
        dist = item.getDistanceTo(own)
        obj = item

# Assign the actuator to track to obj, then activate the actuator.       
Track.object = obj
cont.activate(Track)

Hope this helps

Thanks for the script adrian120396!

Do you maybe know of some other way to make levels?

I’ll list a few ways to make levels that I know of. And hope others chime in.

My favorite way to make levels is by using Blend files. When the player completes the mission on Level_1.blend. It trigger the Game Actuator > “Start Game From File” Level_2.blend, (and so on)
This way you can have as many levels as you want without bogging down the PC.
You can use the GlobalDict to save data from one blend to the other with Python. (Tho it can get tricky, at least for me)
I get my player the way it needs to be first, then make multiple copies for level_1, 2. 3. etc. (I suspect that no one here does it like this)

Another way is to use the inactive layers to create levels, and spawn them when the player completes his mission and end the previous level. If you parent everything in your level to an empty, you only need to spawn the empty, everything else should come with it. You can move your player back to zero with Python, or the Constraint Actuators if you want.
But this way will soon bog down the PC with too many levels.

You could also use scenes as levels, and link your player to each scene (Level). But again, too many levels will bog down the PC.

You could also Libload scenes as levels. But some say it isn’t stable, and may not work on other PCs. And it always crashes on me if I use near, or radar sensors.

You could link levels from other blends. Another good way to create levels.

Then there is procedural generation (?) that I am only just starting to learn. But may prove to be the best way.