Switch Between Clockwise and Counter-clockwise Rotation
iPhoneDevForMe
Member Posts: 362
I have an actor that is falling from the top of the screen to the bottom. I have set up some rules and an attribute to have the actor rotate at a random speed and randomly switch between clockwise and counter-clockwise. Here is what I have so far:
Timer: Every random(2,8) seconds
-Change attribute self.rotation to (self.rotation+1)%2
Rule: If attribute self.rotation is 0
-Rotate clockwise
Rule: If self.rotation is 1
-Rotate Counter-clockwise
I am sure there is probably a much more efficient way to handle this, but my method as referenced above does not work. The actors ALL are at a fixed rotation and do not rotate as they fall.
Any idea's?
Thanks in advance!
Timer: Every random(2,8) seconds
-Change attribute self.rotation to (self.rotation+1)%2
Rule: If attribute self.rotation is 0
-Rotate clockwise
Rule: If self.rotation is 1
-Rotate Counter-clockwise
I am sure there is probably a much more efficient way to handle this, but my method as referenced above does not work. The actors ALL are at a fixed rotation and do not rotate as they fall.
Any idea's?
Thanks in advance!
Comments
If you have the actor set as fixed rotation, it won't rotate.
If you use a random(2,8) in the Timer expression, it will evaluate that random function once, then use that value for the lifetime of the Timer.
What you could do is turn off the Fixed Rotation, Make a timer that every second, change the value of a self.Random attribute to random(1,10), then have a Rule that checks if that attribute is a certain value, to change the Angular velocity to some random number. You can use random(-120,120) as that random expression.
Clockwise and counterclockwise rotations
Actually, CodeMonkey's solution is better (of course): (1) he uses the self.Random attribute to randomize the amount of time for each rotation, and (2) the random angular velocity takes care of the speed and direction of rotation. Very nice, indeed.
As for the random(2,8), this actor is spawned randomly at the top of the screen, so does this mean that every single instance will have the same value when spawned?
I will implement some of these ideas and see what I can come up with! Thanks a lot CodeMonkey and JackBQuick!!