To make every characters go to a certain target whenever you click the ground we create flag
object and set it as a target for the selected characters,
when all the characters reaches the flag, it gets deleted
Details :
we have the function main()
which is excuted when you MMBclick on the ground this function :
- creates a new Flag object at cursor position
- loop through all objects and find the selected ones that have
Move
property,
for each found object :
- change the
Steering
actuator target
to this new Flag
- increment the Flag
Followers
property by one
- set the object properties
Active
and Move
to True
- when Active and Move are set the object start seeking the flag
this is done with this part of code :
main():
.......
flag = scene.addObject("Flag", "Tracker", 0)
for obj in scene.objects :
if obj.get('Select', False) and 'Move' in obj.getPropertyNames() :
obj.actuators["SeekTracker"].target = flag
obj['Move'] = True
obj['Active'] = True
flag['Followers'] +=1
The Flag has property Followers
which indicate how many objects have it as a target, so if it has no followers it should be removed , for this we have a function flag_self_check()
which does that, the code part for this is :
def flag_self_check():
cont = logic.getCurrentController()
own = cont.owner
if own['Followers'] == 0 :
own.endObject()
but what makes the Followers
count goes down ? it is the object, the moving object has a near sensor to detect the flag when the object gets near the flag it stops Moving and decrement the flag Followers
count by one
def reach_dest():
cont = logic.getCurrentController()
own = cont.owner
sen = cont.sensors["Near"]
if sen.positive :
hit_flag = sen.hitObjectList[0]
if hit_flag :
if hit_flag == target :
hit_flag['Followers'] -= 1
own['Move'] = False
i have added if hit_flag == target :
so moving object don't stop at the wrong flag when passing by
