move an actor radomly

thelittledevilthelittledevil Member Posts: 5
edited November -1 in Working with GS (Mac)
Does anyone know how to make an actor move by itself in a ramdom way? to make it clear like the movement of flies.

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Use a mix of Interpolate and Timers, like this:

    In the actor, create two integer attributes: randomX and randomY

    Then set up a Timer, like this:

    Timer Every 2 seconds
    -----Change attribute: self.randomX To: random(0,480)
    -----Change attribute: self.randomY To: random(0,320)
    -----Interpolate self.Position.X To self.randomX duration 2 seconds
    -----Interpolate self.Position.Y To self.randomY duration 2 seconds

    Something like that should do it.
  • thelittledevilthelittledevil Member Posts: 5
    I can't make it work. How can I put the "self.randomX" or "self.randomY"??? everytime I write it down at the change attribute it changes to "game.randomX"

    the rest is ok. It doesn't change
  • Rob2Rob2 Member Posts: 2,402
    you can get away without the change attributes
  • StusAppsStusApps Member, PRO Posts: 1,352
    When you are inside that actor click the plus on the left of the screen and make an attribute for just that actor.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Oops. Yes, rob is correct.

    Forget the attributes. Just use:

    Timer every 2 seconds
    -----Interpolate: self.positionY to: random(0,320) 2 seconds
    -----Interpolate: self.position.X to random(0,480) 2 seconds
  • thelittledevilthelittledevil Member Posts: 5
    heyyyyy that was perfect. It works now!!!

    THANKS!!!
  • thelittledevilthelittledevil Member Posts: 5
    Ok another problem. Is there any way to make the actor rotate so every time it changes it's path it is looking to the new direction?

    By now it moves around as I was expecting but it looks like it's moving backwards or from left to right... as it doesn't rotate with every change.
  • synthesissynthesis Member Posts: 1,693
    To do that...you will need to track the X and Y target position and then use the rotate to position behavior.

    Ex:
    self.TargetX=random(0,360)
    self.TargetY=random(0,480)
    Interpolate: self.position.Y to self.TargetX (2 seconds)
    Interpolate: self.position.X to self.TargetY (2 seconds)
    rotateToPosition: self.TargetX and self.TargetY

    Another way is to do this:

    self.TargetX=random(0,360)
    self.TargetY=random(0,480)
    rotateToPosition: self.TargetX and self.TargetY
    Move

    Place that inside a timer if you want it to change direction every few seconds.
  • thelittledevilthelittledevil Member Posts: 5
    Do I have to create an Integer for those Target.x and Target.Y because I can't find it anywhere!!
  • Rob2Rob2 Member Posts: 2,402
    @fmg...what about smooth continuous movement at a constant speed...a whole new approach required?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @rob: I actually need something like that in my new game. I have a fish swimming around. I was going to try to have a zigzagging actor like described above. And the fish follow it with a move to behavior or something. I'll be tackling that in the next few days and I'll let you know.
Sign In or Register to comment.