Move an actor, randomly within the limits of the x axis.
picoalex
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
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
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.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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.
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.
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.
read the GS manual, it takes time but you will understand the basic things.