Best way for AI to scan with multiple instances?
HappyKat78
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
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
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
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
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User