Looping/repeating a behavior
This is probably easy but I can't get the site search to work worth beans right now and all the cached links go nowhere.
I have an actor that I want to simply rotate a few degrees clockwise, then counter clockwise to the original position and repeat. I have been playing with the timer + the rotate behavior and I can get the actor to do what it is I need to, I just need to loop these behaviors. Sooo close... I don't want to have to create this simple animation in flash if I don't have to. Any ideas? I'll keep playing with it, but something tells me it might have to do with Attribute-land.
I have an actor that I want to simply rotate a few degrees clockwise, then counter clockwise to the original position and repeat. I have been playing with the timer + the rotate behavior and I can get the actor to do what it is I need to, I just need to loop these behaviors. Sooo close... I don't want to have to create this simple animation in flash if I don't have to. Any ideas? I'll keep playing with it, but something tells me it might have to do with Attribute-land.
Comments
Alright, let me try these out. Thanks!
Addendum: I'll have to remember this mistake I made, it gives off a great exaggerated clock hand effect.
http://dl.dropbox.com/u/2816426/gamesalad files/rotating effect.zip
EDIT: i realize this is going the wrong way, but you can easily change the angle.
Really, really loving Gamesalad right about now (thanks for the examples!). Oh man!!! Why did I ever go with Torque?????!!! What was I thinking?
GS is excellent, agreed, it's going to be blinding by 1.0, I reckon! :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@ muoch10 no joke! things just make so much more sense here with GS and the community is great. Torque has some great folks too, but resources were often out of date and code often broken and unusable.
I had pretty much the same issues as you were having, I wanted an object to rock back and forth a few degree - and I also played with timers which had rotate commands embedded in them (which were less than ideal) and I also had the issue of the slight delay before the rotation starts (the timer needs to run for one iteration first - even on a 'every' setting . . . ?).
Anyhow, this is my solution, no timers, no rotations one way and then a separate timer and a separate rotation the other way, no annoying delay at the start and just one line of code . .
Constrain Rotation to . . . (5*sin((self.Time *2000)%360))
The red number is the degree of rotation (5° in my example).
The purple number is the speed of the rotation (2000 in my example).
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Accept for the part when 2000 is written in cyan when it should be purple (the forum won't let me edit it).
You can also use the same formula to shake stuff about, it works really nicely, like this
Constrain X (or whatever) position to . . . . . . (5*sin((self.Time *2000)%360))+512
Again the 5 is the degree of movement, the 2000 is the speed of movement - and the '+512' I've added on the end is the offset (so this is placed right in the middle of the screen - left to right)
X and Y position and Rotation together give you a nice cartoony movement.
Y position = (2*sin(( self.Time *2000)%360))+(the Y position you want the shaky thing to be)
X position = (2*sin(( self.Time *2000)%360))+(the X position you want the shaky thing to be)
Rotation = (6*sin(( self.Time *1000)%360))
Play around, make some values negative, chuck in an extra multiplier here and there, try using cosine ('cos') instead of sine ('sin') (although all this does is offset the phase of the sine wave by 90°) - and you get some nice wobbly effects.
On the sine wave based rotation if you want your actors starting rotation to be something specific simply add the offset you want to the end of the equation.
So . . . . (5*sin((self.Time *2000)%360)) . . . is normal.
And . . (5*sin((self.Time *2000)%360))+90 . . . is the whole thing offset by 90°.
And . . (5*sin((self.Time *2000)%360))+180 . . . is the whole thing offset by 180°.
etc.
And . . (5*sin((self.Time *2000)%360))+(self.Time *20) . . . is a wobbly shaky thing that turns while wobbling and shaking like a second hand on a old cartoon clock !
And . . (44*sin(( self.Time *1000)%360))+( self.Time *( self.Time * self.Time )) . . . is the exact movement of a convulsing duck who has contracted bird flu. (keep you finger on the mouse)
Wow! Just got saw this. Many, many thanks!
Yeah ! It's good stuff, it's also really easy to understand if you imagine cos (or sin) is simply the 'path' a value takes as it travels around a circle.
Once you have this concept in your head you can do all sorts of really cool stuff with it.
If you added the "sin", velocity and area of the circle and changed things around a bit added some art, the you'd have a 3d illusion of the circle!
It's always difficult to sound sarcastic only using maths . . .
: )
Ya!! That something my maths teacher never realised!!
There's some sarcasm for ya!
Just play around with the sin values until your balls are moving the way you like them to move.
(is it just me or has this thread taken a worryingly homoerotic turn ?)
: s