GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Looping/repeating a behavior

RPRP Posts: 1,990Member
edited December 2011 in Working with GS (Mac)
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.

Comments

  • muoch10muoch10 Posts: 112Member
    edited December 2011
    ok so for this example ill say rotation j = ur first rotation degree, and k is the second. it just makes it easier to explain. so have a rule and say when self.rotation = j interpolate self.rotation to k. make another rule when self.rotation is k interpolate self.rotation to j. This will make the actor rotate to j then to k then to j and so on.
  • RPRP Posts: 1,990Member
    edited December 2011
    Sweet, I'll try those next. I almost had it!!! I had the rocking effect, but my actor ended up doing a 360 in the end anyway. Relying on the timer and rotate alone is a no-go.
    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.
  • muoch10muoch10 Posts: 112Member
    edited December 2011
    here is the project to see the 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.
  • RPRP Posts: 1,990Member
    Actually I got it just using the timer and rotation right after I posted that. only issue now is it has a slight delay before the rotation kicks in (it's a game over screen and it needs to start the rocking the instant it goes to that scene. Going to try the Boolean next to see if it cleans it up.
  • RPRP Posts: 1,990Member
    Awesome! Thanks muoch10 that is what I was looking for.
  • muoch10muoch10 Posts: 112Member
    No problem. If you have any more questions you can just ask
  • RPRP Posts: 1,990Member
    Thanks gyroscope! Nice to see there are different ways to do this. I had something similar to you minus the first attribute.

    Really, really loving Gamesalad right about now (thanks for the examples!). Oh man!!! Why did I ever go with Torque?????!!! What was I thinking?
  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO
    edited December 2011
    Hi RP: Whoops again big time – I thought you didn't have any forum etiquette and I was being ignored when I tried to help so I deleted all my comments... apologies to you ...... (I get like that when I'm tired, sorry again...)

    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

  • muoch10muoch10 Posts: 112Member
    yeah, gamesalad is a dream, especially coming from objective c. everything is so quick and easy in gamesalad.
  • RPRP Posts: 1,990Member
    No worries Gyroscope! I was troubleshooting at the same time. The help is much appreciated.

    @ 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.
  • CloudsClouds Posts: 1,599Member
    @ RP
    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 ( in my example).
    The purple number is the speed of the rotation (2000 in my example).



  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO
    Hi Tynan, that's really impressive. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CloudsClouds Posts: 1,599Member
    edited January 2012
    Hi Tynan, that's really impressive. :-)

    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.
  • CloudsClouds Posts: 1,599Member
    P.S. . . . because we are using a sine wave all movements and rotations are naturally dampened at their extremes so you get quite a natural movement, I'm trying to figure out how to do linear movements (like a sawtooth wave) . . . . which might also be useful.
  • CloudsClouds Posts: 1,599Member
    edited January 2012
    P.P.S

    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)



  • RPRP Posts: 1,990Member
    @ Tynan

    Wow! Just got saw this. Many, many thanks!
  • CloudsClouds Posts: 1,599Member
    edited January 2012
    "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.
  • LeonardDeveloperLeonardDeveloper Posts: 4,630Member
    @tynan
    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! ;) edit: (this isn't sarcasm by the way, I know it sounds like it but I'm not messing around, I use that method a lot for circles)
  • CloudsClouds Posts: 1,599Member
    "This isn't sarcasm by the way, I know it sounds like it but I'm not messing around"

    It's always difficult to sound sarcastic only using maths . . .

    : )
  • LeonardDeveloperLeonardDeveloper Posts: 4,630Member
    @tynan
    Ya!! That something my maths teacher never realised!! :)
  • RPRP Posts: 1,990Member
    edited January 2012
    Okay I got the sin part, but where do I insert the punishment?

    :p

    There's some sarcasm for ya!
  • CloudsClouds Posts: 1,599Member
    @ RP "Okay I got the sin part, but where do I insert the punishment?"

    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
  • RPRP Posts: 1,990Member
    lol nice. Seriously though thanks guys, this will help big time and keep me less dependent on other apps for more simple animations (keeps those file sizes down too!).
This discussion has been closed.