Help Working With Actors Spawned In-Game
AirbornGames
Member Posts: 0
Alright, I'm trying to make a totally procedural Empire Earth type thing, less of a game and more of a project, and part of it needs to have people scavenge for food by themselves. The problem i'm having is, I can't seem to find a way to make it so that the people go to the nearest berry bush, that is spawned randomly. Everything is supposed to be spawned in-game, so that limits my options a lot. I also cant have it save the berry's coordinates in the Game section because there will be a lot of them, and I won't be able to tell how many spawn before hand. Any help is appreciated.
Comments
I'll give you my best answer:
When each berry bush spawns, it checks its distance (magnitude) from the "people" actor* and if it is closest it changes game.ClosestBerryX and game.ClosestBerryY to its own self.position.X and self.positionY, and game.ClosestBerryDistance to its own distance from the people. Initially, game.ClosestBerryDistance would be set to a large number (e.g. 9999) so the first bush that spawns would change it and then the next bush would check to see if its distance is less than game.ClosestBerryDistance.
*I'm hoping there's only one "people" and not a bunch of individual "person" actors.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
My solution, so far, is to assign each "berry bush" to a table cell based on what order they're spawned in, and read data from that table when there's a state change. In my case, it's a radio being turned on/off that an enemy will react to if they're within "hearing range." I spawn a hidden collider with the width of the range, and if the enemy is close enough they'll collide with it and move to the center x/y location, which is the same as the radio. If the radio is turned off, the invisible collider, which reads a value from a table to check for radio on/off state, is deleted.
It's a pretty roundabout way to do things, but it mostly works as it should, with the occasional quirk due to how painfully slow GS reads data from a table, but that's probably (hopefully) a solvable issue.
In another tool (straight java, c#, XNA, Unity, Game Maker) I could have the objects talk to each other a bit more. Like, at all . If I remember correctly, melon.js, an HTML5 game development framework, supports more direct object interaction as well. Now that I think about it, it might also support pulling tilesets from Tiled. Hmm.