Move an actor, randomly within the limits of the x axis.

picoalexpicoalex Member Posts: 13
How move an actor, randomly within the limits of the x axis.
How can I do?
This actor when he goes to the right must have an animation to the right, when he goes to the left must have an animation to the left.
But the movement must be random.
This actor should not come out from the screen, but it must stay within the limits, and when about to leave to go back

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Just put a random expression in there -

    You could do something like this:

    Timer: every 5 seconds,
    Move To: (In the X value) Random(10,470)
    (Y value) Random10,310)

    This will move your actor every 5 seconds to a random location on the screen without the actor leaving the screen.

    Hopefully this gets you on the right track.
  • picoalexpicoalex Member Posts: 13
    thanks for the answer :)! I do move the actor only in the x, and I have to animate when it goes right, and when he goes to the left. how can I do that?
  • famekraftsfamekrafts Member, BASIC Posts: 834
    edited October 2012
    By finding its direction, if it's moving towards the left (set up attributes to figure that out) if it's 1 change image to left if its 2 change to right. If you using animate behaviour simply spawn actor left or right with different animation at self.position x when the change happens and destroy the previous actor.
  • picoalexpicoalex Member Posts: 13
    please can you show me an example? thank you for your patience
  • famekraftsfamekrafts Member, BASIC Posts: 834
    edited October 2012
    I am on my iPad, was going to sleep. Will getup in morning and try making a demo for you if by then no one has helped. Get the basic idea if self.position x is random(1,420) thats the screen size for iPhone.

    Then make attribute direction to be random(1,5)

    If direction is 1 spawn actor left and move direction 180, destroy the current one.

    If direction is 2 spawn actor right and move direction 0, destroy current.

    Rest 3 to 5 attribute is so that nothing happens and thus sometimes it will move in one direction longer or shorter period of time. If its changing very fast use more numbers say till ten or use timer.

    Also if it goes out of screen you can make it come back by making an invisible wall so that it's direction changes to opposite using direction attribute 1 or 2 on collision.

  • famekraftsfamekrafts Member, BASIC Posts: 834
    Instead of the Walls you can try if x position is > 423 change direction to left, and opp for < 0
  • GLGAMESGLGAMES SingaporeMember Posts: 988
    edited October 2012
    Something like this perhaps?
    http://screencast-o-matic.com/watch/cl6bhkRug
    Will need some refining to get it working nicely. I'm using simple interpolate self.postition.x at every 8 sec. so the movement speed differs everytime due to distant/8sec = varies speed.
    directional change a bit buggy still cos i'm only using comparision between current.x and oldposition.x
    current.x > oldposition.x change image to right face
    current.x < oldposition.x change image to left face
    current.x = oldposition.x change image to stop.
  • picoalexpicoalex Member Posts: 13
    thanks! ! :) so I'll try. I keep you update..
  • picoalexpicoalex Member Posts: 13
    thanks! ! :) so I'll try. I keep you update..
  • picoalexpicoalex Member Posts: 13
    not display any image when I click the link http://screencast-o-matic.com/watch/cl6bhkRug
  • picoalexpicoalex Member Posts: 13
    solved! I had a problem Java .. thanks now I try! :D
  • picoalexpicoalex Member Posts: 13
    using the function change image, the object is animated?
  • GLGAMESGLGAMES SingaporeMember Posts: 988
    animate is using a sequence of images whereas change image is only 1 static image.
    Thus if you want a walking animation then you have to use animate. Cos my example is static image so i just change it according to direction.
  • picoalexpicoalex Member Posts: 13
    you can write me step by step how to do? thanks for your help and above all patience. I am learning to use GameSalad
  • picoalexpicoalex Member Posts: 13
    anyone help me?
  • famekraftsfamekrafts Member, BASIC Posts: 834
    Open your actor, drag and drop the animate behavior in it, drop your animations in the animate behavior, of one type, for example its moving left, so all the left animation. You have to make separate actors for each direction.

    read the GS manual, it takes time but you will understand the basic things.

Sign In or Register to comment.