random movement

RocketBrainRocketBrain Member, PRO Posts: 269
edited November -1 in Working with GS (Mac)
I cant seem to find a way to get an actor to move randomly along the x-axis.

is this possible? i tried to fake it by creating multiple actors that could bounce off of eachother offscreen but theres gotta be an easier way.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    can you be more specific. Move at a random speed? At random times? Randomly chose left or right?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    random movement side to side, random times, dancing a jig if you will ;)
  • RocketBrainRocketBrain Member, PRO Posts: 269
    still nothing? been working on this for several days.....
  • synthesissynthesis Member Posts: 1,693
    set a switching boolean attribute called moveRight defaulted to TRUE
    and an integer attribute for the XtargetPos

    Rule when self.moveRight = true
    ...self.XtargetPos = random(190-300)
    ...interpolate self.Position.X to self.XtargetPos
    ...Rule (embedded) >> when self.Position.X = self.XtargetPos then self.moveRight = false

    Rule: when self.moveRight = false
    ...self.XtargetPos = random(20-130)
    ...interpolate self.Position.X to self.XtargetPos
    ...Rule (embedded) >> when self.Position.X = self.XtargetPos then self.moveRight = true

    You could also make the speed of the interpolation a random number so the speed he moves will vary.
  • Don't mean to hijack, but I have a similar problem. Isn't there an easier way? I am a total noob and I have a character that I need to just move side to side. Little bit to the left and then a little bit to the right. In a loop, unless touched. That's it, I figured it should be a simple move command, but what you typed above doesn't look like "game creation for the rest of us" kind of info. What the heck is a switching boolean? Sorry, just really new to this.
  • synthesissynthesis Member Posts: 1,693
    @delorean...

    The above is the easy way...
    The hard (but more elegant) way is to write a trigonometry algorithm in the expression...yes that SIN, COS and TAN stuff most of you hate.

    If you care to investigate it...here is a demo...
    http://gamesalad.com/game/play/47300

    BTW:
    a switch boolean is a TRUE/FALSE attribute....that can be used like a light switch. You can use another actor or a game controller to make it true or false (if a game attribute). When true...it turns on...when false it sits still.

    In the above example...The switch is for the moving right. If true...the actor executes the right moving rule set.

    When false...then the actor executes the non-true/non-right moving rule set...in this case to move left.

    I recommend you do some heavy reading in the support section about some of the baseline reference stuff and demos...it will help you with the "lingo".
  • RocketBrainRocketBrain Member, PRO Posts: 269
    thanks synth, i'll give that a try tonight.

    my creative alternate kinda worked.

    [bumper] <-> [bouncer] <-> [stabilizer] <-> [bouncer] <-> [bumper]

    bumpers cant move
    added accelerate to each bouncer telling at certain timers to head to the middle. Stabilizer had no friction and could bounce off each bouncer.

    by changing the timing and position of the bouncers it created an almost random effect on the stabilizer. make it all hidden in the background, except for the stabilizer and voila. imagine its a bit of a memory hog.

    hopefully i can get your way to work synth.
  • ORBZORBZ Member Posts: 1,304
    There is a much easier way:

    Timer every 0.5 seconds

    Interpolate self.motion.LinearVelocity.X to:random(-4,4)*50 duration:0.25 seconds

    Here's an example I made:

    http://gamesalad.com/game/play/79713

    Enjoy :)
  • houenhouen Member Posts: 7
    Awesome Orbz! Nice trick
Sign In or Register to comment.