Is it Possible to Avoid Group Instances from Interfering with each other via Python?

So I’m trying to recreate the Cockroach AI from Half-Life 1 or at least make something similar to this:

So I created a small Forklift Demo that does a very similar thing:

with a Single Group Instance its works greats but when having more than one they just hump up against a wall and do nothing:

So I was wondering if it would be possible to add a python script to the original object that makes it so each instance of the group is an Individual Instance this way it doesn’t interfere with the other instances wandering around the level?

But if there is no way of doing this I was also thinking about just having a room separate from the play area where the Forklifts are stored and just teleport them via empties and triggers to the location I need them similar to how it works in the GoldSRC engine:

Sorry if the Solution is painfully obvious I’m still a Python newbie but i want to learn more :smile:

Post your python code here, then every one will try and help.

1 Like

Didn’t really find anything useful while reading around the forum so I’m using the GoldSRC Method of just having the forklifts stored in a far away room and then teleported in with a trigger

Teleport_Thing.py (1.1 KB)

I’d suggest using object simulation to make your group instances avoid colliding with one other.

1 Like

From a glance the script is hard coded by name and not using cont.owner and owner.children

This will make the script fail for 2

Also post the code in code brackets like this

Here is my code
1 Like

Here is the Script !
NPC_Forklift.py (1.7 KB)

.py can actually be a attack vector :stuck_out_tongue:

If you paste the code here I will help you.

I will not download a blend or a .py

1 Like

the code :smile:

import bge
import mathutils
### Get Current Scene ###
scene = bge.logic.getCurrentScene()

### Get Current Object ###
cont    =   bge.logic.getCurrentController()
own     =   cont.owner

### Get Perpendicular Lines ###
ObjPosY = scene.objects['G_ForkLift_Arrow(+Y)']

### Get Diagonal Lines ###
ObjPosD = scene.objects['G_ForkLift_Arrow(+D)']
ObjNegD = scene.objects['G_ForkLift_Arrow(-D)']

### Get Main Sensors ###
Active  =   own.sensors['Active']
Active  =   ObjPosD.sensors['Active']
Active  =   ObjNegD.sensors['Active']

### Get Perpendicular Sensors ###
PosY    =   ObjPosY.sensors['PosY']

### Get Diagonal Sensors ###
PosD    =   ObjPosD.sensors['PosD']
NegD    =   ObjNegD.sensors['NegD']

### Logic Perpendicular Lines ###
if (Active.positive) and (PosY.positive) and not (PosD.positive) and not (NegD.positive):
    own.localOrientation    =   (0,0,-180)
   
### Logic Diagonal Lines ###
elif (Active.positive) and (PosD.positive) and not (PosY.positive) and not (NegD.positive):
    own.localOrientation    =   (0,0,-45)

elif (Active.positive) and (NegD.positive) and not (PosY.positive) and not (PosD.positive):
    own.localOrientation    =   (0,0,45)

### Logic Misc Lines ###
if (Active.positive) and (NegD.positive) and (PosY.positive) and (PosD.positive):
    own.localOrientation    =   (0,0,180)

elif (Active.positive) and (NegD.positive) and (PosY.positive) and not (PosD.positive):
    own.localOrientation    =   (0,0,90)

elif (Active.positive) and (PosD.positive) and (PosY.positive) and not (NegD.positive): 
    own.localOrientation    =   (0,0,-90)

### Logics move forwards ###
if (Active.positive) and (PosD.positive) and (NegD.positive) and not (PosY.positive): 
    own.localOrientation    =   (0,0,0)

there is no autopilot code here, are you trying to control them both at the same time?

also there is external objects involved for no reason - why not use a keyboard sensor?

also this code is kinda silly / overcomplex(Active is redefined many times?)

what are you trying to do?

1 Like

I’m trying to make a simple ai that just wonders around the level. The multiple actives where a work around that didn’t work. You only need the first active the other two con be removed

python scripts works for a single object if connected to multiple objects. But they all do stuff? Yes because it grabs data from 1 object and uses that data for all objects connected to it.

How to fix?
Simple, use functions.

def AI_wander():
    #your script here

Now in the objects python brick…

  • click on the script and change it to module
  • now enter the scriptname and follow with a . and your function name like this: scriptname.AI_wander

Make sure your python file/script name ends with .py in the text editor.

That’s it.

1 Like

Posting the Blend here incase anybody wants to check it out

Roach_Demo.blend (633.7 KB)

Ah, you just have to call the sensors related to your object instead of directly.
change this part:

    ### Get Diagonal Lines ###
    FRay    = scene.objects['NPC_Roach_FRay']
    LRay    = scene.objects['NPC_Roach_LRay']
    RRay    = scene.objects['NPC_Roach_RRay']
    ### Get Main Sensors ###
    Active  =   own.sensors['Active']
    
    ### Get Sensors ###
    Front    =   FRay.sensors['FRay']
    Left     =   LRay.sensors['LRay']
    Right    =   RRay.sensors['RRay']

into this:

    ### Get Main Sensors ###
    Active  =   own.sensors['Active']
    
    ### Get Sensors ###
    Front    =   cont.sensors['FRay']
    Left     =   cont.sensors['LRay']
    Right    =   cont.sensors['RRay']
1 Like

thanks for the help guys !!! did some more messing around here is the Blend incase anybody needs a cockroach AI for their project :rofl:

Roach_Demo2.blend (1.5 MB)

2 Likes

vision_cone_with_raytest_0_2_5b.blend (600.3 KB)
check this out for roaches that Fightchya

vision_cone_with_raytest_0_2_5_c.blend (589.7 KB)
(cleaned up prints and added comments)

1 Like