Best way for AI to scan with multiple instances?

HappyKat78HappyKat78 Member, BASIC Posts: 173
Hi Guys,

I'm sure this has come up before but can't find anything on it. Let's say I have a top down game with a number of player and enemy instances (think all-out warfare, where they're all heading towards each other!). What's the best way for each actor (instance) to recognize when any enemy actor (instance) is directly ahead within a certain distance (say 100 pixels) and then stop and start firing??

I'm fine doing this with just a couple of actors/instances but not sure how to scale this with multiple instances needing to react to other multiple instances.

Thanks,

HK

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2013
    One way is to constrain a "radius" actor (circle with radius=100) to each enemy and when the player collides with the radius, have it stop and fire.

    The method I demo'ed here can be used to constrain any sort of actor to an existing actor: http://forums.gamesalad.com/discussion/comment/384027/#Comment_384027.

    It's not very processor-friendly because of all of the constrains, but it can work.

    If you had a great deal of order to your game (e.g. grid spacing, enemies only move in straight lines), it could be much simpler to determine distance. You could have waypoint actors that when collided with by an enemy alert the player to stop and fire.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Thanks very much for the health bar demos, they will come in handy! Yeah, I thought about constraining a "sensor" actor to each instance, although I don't want it searching 100 pixels on a 360 degree, I only want to check 100 pixels in front of the actor, so needs to rotate etc. with the actor and continuously stay in front of it. Not sure if this is easy. I've tried assigning a table (much like your health bars) that has X, Y and Rotation variables constantly updating but the frame rate dies a sad death. Not sure I'm doing it right?! Let me know if you have any other suggestions! Thanks!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    True, with that many constraints, especially with a large number of actors on screen you're looking at sub-par performance. I'm not sure how else to do it.

    Actually... this just came to mind: have each actor fire an invisible bullet. Keep track of which actor it came from (use my health bar demo... let me know if you need help adapting it for bullets). Have the bullet destroy itself after it has traveled 100 pixels. If the bullet collides with an enemy, tell the player actor to stop moving and begin firing.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Funny.... I have actually been working on exactly that!! Yeah, I've been struggling a little to assign each bullet to each instance of an actor as the actor needs to fire bullets every second or so in order to test for the 100 pixel rule. Also, still trying to figure out how to angle the bullet to that of the actor too. If you have a demo then that would be amazing, but otherwise I'll keep basing away at this idea! Thanks very much for your help!!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2013
    If you import your images facing to the right (self.Rotation=0), then you can fire bullets at 0° relative to actor and they will fire in the correct direction each time.

    The way the health bar demo works is to set a spawn index right before spawning and then the bar actor assigns that spawn index to itself and uses it after that. So a bullet would work the same way: the player actor increases an integer attribute and the bullet actor assigns and uses that same value. I created a demo recently that does just that (the bullet spawning and assigning, not the range-finding)... I'll see if I can find it.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here you go:

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    This looks great! thanks so much. I'll have a play around with this and see if I can make it work! You rock! cheers!
Sign In or Register to comment.