Help Working With Actors Spawned In-Game

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

  • PixelMetalPixelMetal Member Posts: 283
    edited December 2012
    I'm having a similar issue with procedural content, I'd be curious to hear from anyone with experience doing it in GS as well. It's so simple using other development tools...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    @PixelMetal, can you describe how it's done with other tools? Sometimes knowing the algorithm can allow us to translate it to GameSalad.

    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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's a demo. It's a bit buggy but generally if you click on the "people" actor, that actor will move to the closest berry bush.

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

  • PixelMetalPixelMetal Member Posts: 283
    edited December 2012
    @PixelMetal, can you describe how it's done with other tools? Sometimes knowing the algorithm can allow us to translate it to GameSalad.

    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.
    This is pretty similar to what I'm trying to accomplish, though in my case there are multiple "person" actors.

    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.

Sign In or Register to comment.