2
$\begingroup$

In a follow up to this fantastic question that I've been waiting for some one to ask, I would like to know how I can send d people in an RTS game to different locations. I already have an empty being added with a different property each time I click, but I don't know how to get flocks to only steer toward an object with a certain property, and not just the object.

How can I set an object to only seek empty with property[goto]=1 while anoter group is seeking empty with property[goto]=2, and so forth? This would be really helpful, thanks.

$\endgroup$
  • $\begingroup$ can you provide a .blend to start with ? $\endgroup$ – Chebhou Apr 5 '15 at 1:42
  • $\begingroup$ Already done. :D $\endgroup$ – Scalia Apr 5 '15 at 1:50
2
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.