Issue spawning moving obstacle from tables

Hi all,

So I have a game prototype I am working on where the hero dodges incoming obstacles. To do this, I have the hero constrained to the screen area, spawn obstacles off the screen, and tell the obstacles to move toward the hero. To spawn obstacles, I keep track of the hero's distance traveled in the x direction (though this is a "fake" distance traveled, its actually the objects who move toward the hero). Every certain amount of distance, I trigger the obstacle spawn. The obstacle spawn reads x,y locations from a table, and spawns an obstacle at each x,y pair to form a grid of obstacles.

The problem I am having is that the obstacles do not spawn all at the same time. The spawn rule spawns one row, then the next, then the next, etc. There is a small and variable amount of lag between each spawn, which means the obstacles don't stick to the initial grid from the table. Since the obstacles start moving as soon as they spawn, when one obstacle spawns before another one, the distance between them changes. What I would like is to have a fixed distance between the obstacles when they spawn (spawn in the table grid locations) so I can make complex grid shapes for the hero to weave through.

Does anyone have any suggestions to fix this problem?

Thanks,
AirshipScientist

Comments

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

    Have you tried using a timer or a loop to spawn the actors? How do you have the rule setup for "Every certain amount of distance"?

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

  • AirshipScientistAirshipScientist Member Posts: 21

    @tatiang

    I don't have access to the loop command, but I do currently have the spawn going off a timer. When the spawn triggers, to spawn my grid of obstacles, every 0 seconds, spawn an actor at position x,y coordinates from row 1, iterate to row 2, spawn at those coordinates, and so on until the end of the table. There still seems to be some delay between spawning the different actors in that loop.

    My rule for spawning works like this: There is a game variable, game.traveled. Every 0.1 seconds, I change attribute game.traveled to game.traveled + hero.speed/10. When game.traveled > 480*game.spawn, activate the spawn rule and iterate game.spawn to game.spawn + 1. That way, a new set of obstacles spawns every time the hero moves 480 in the x direction. Hope that makes sense.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2014

    Well if you're using a Timer like this:

    Timer every 0 seconds spawn actor [actor name] at tableCellValue(tableName,game.row,1) tableCellValue(tableName,game.row,2) change attribute game.row to game.row+1

    Then you're going to have a very short delay between iterations. "Every 0 seconds" timers fire every 0.03 seconds or so. You can see that by placing a Log Debugging Statement with game.Time in the expression and then watching the Debugger window.

    There are faster looping methods.* If you search the forums for Fast Loop, you'll see examples of "Fast For Loop" and "Hyper Loop." I also have a Study of Loops file that while not quite as fast as those methods is a bit easier to comprehend.

    http://forums.gamesalad.com/discussion/comment/381275/#Comment_381275

    *If you aren't spawning tons of actors, you might consider just using multiple Spawn Actor commands in a single rule.

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

  • AirshipScientistAirshipScientist Member Posts: 21

    @tatiang

    Yeah, that timer example is exactly what I am doing. I might be able to get away with multiple spawn actor commands in a single rule. Would that delay be less than the 0.03 second delay from the timer/table method? I will certainly look into alternate faster looping methods. Thanks for your suggestion.

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

    Using multiple spawn actor behaviors should result in no delay.

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

Sign In or Register to comment.