move an actor radomly
thelittledevil
Member Posts: 5
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
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.
the rest is ok. It doesn't change
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
THANKS!!!
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.
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.