randomize motion & bullets firing by bossman

jorkosjorkos Member, PRO Posts: 353

Hey guys, in my new game I have an end of level scene where a bossman moves back and forth between two Y positions and fires bullets. I want to randomize how it moves between these two Y positions and very where it changes. Also, I want to very how often the bossman fires bullets (ie. between 3 and 7 seconds). Any ideas? Thanks for your help.

Comments

  • TosanuTosanu Member, PRO Posts: 388
    edited April 2014

    Well, for the bullets, you should be able to use a timer with an attribute that is determined within the timer as random(3,7) for the value if you don't need any specific variance or patterns, so that it repeats and rechecks, I believe.

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

    @Tosanu Using a random() function inside of a Timer behavior doesn't work because Timers set their duration once and then use that duration the entire time the Timer is active.

    You'll have to use a custom timer. Here's a demo: http://forums.gamesalad.com/discussion/comment/464547/#Comment_464547

    For random movement within a range, create random movement rules (for example, by using a custom timer) and constrain the actor's position:

    Constrain attribute self.position.Y to max(self.actorMinY,min(self.actorMaxY,self.position.Y)).

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

  • TosanuTosanu Member, PRO Posts: 388
    edited April 2014

    @tatiang‌ Does that include even when the expression is not inside the timer's line? My thought, and something I was planning for my own game, was to have it trigger inside the every timer's set of functions, a Change attribute, so that when it reactivates on the next loop the expression changes. Is that impossible?

  • joshiwujoshiwu Member Posts: 207

    Tatiana the random function in your time isn't recalculating, BUT if you take all that and put it in another timer for every 2 seconds, it will regenerate another random number in the timer.

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

    @Tosanu‌ If you put a mathematical function inside of the timer expression, it won't change after the first calculation. Or say you just used an attribute called game.duration and you changed its value somewhere else... it still won't change the duration of the timer. The timer is "locked" after the first time it runs and there is no way to change the duration using the standard Timer behavior.

    @joshiwu I'm not sure what you mean...? In the demo I posted, the "timer" chooses a different random duration each time. It is possible to repeat durations, of course (e.g. 3 seconds, 6 seconds, 6 seconds, 4 seconds, ...).

    Here's what the Debugger window shows when I run the demo*:
    Log(Actor: custom timer): 0 Log(Actor: custom timer): 3 Log(Actor: custom timer): 8 Log(Actor: custom timer): 11 Log(Actor: custom timer): 18 Log(Actor: custom timer): 21

    *The values are game.Time rounded to the nearest second. So if you subtract, you'll get the duration for each interval/iteration:

    Log(Actor: custom timer): 0 Log(Actor: custom timer): 3 <-- 3 seconds Log(Actor: custom timer): 8 <-- 5 seconds Log(Actor: custom timer): 11 <-- 3 seconds Log(Actor: custom timer): 18 <-- 7 seconds Log(Actor: custom timer): 21 <-- 3 seconds

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    Random(ish) Y movement.

    Link: https://www.mediafire.com/?780sdge66erauhn

Sign In or Register to comment.