How to create custom rotation - rotates in one direction for a small time period then another

Hi,

I want my actor to accelerate and rotate in one direction for a certain ammount of time and then rotate in another direction (oppsite to before) for another ammount of time. So it looks like the actor is 'wavey'

If you google - Sin Graph I want it to look wavey as it accelerates like that. - kind of like a custom axis.

I know how to accelerate the actor and make it rotate just not like this, I've been looking for the solution online but haven't found anything that works.

Any help?
Thanks a lot - I appreciate it

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    @hamzeyyy Hi, are you certain you want acceleration each time? Especially if the rotation one way then the other is over a short time, you're not going to see much acceleration....

    Here's a gamefile test showing an actor rotating one way then the other, over and again, giving a "wavy" impression as you want (although I'll say again without any acceleration involved). Hopefully you'll live with it for what you want.

    Note: the algorithm used in based on one given by @Socks - to give credit there... (A*sin(self.Time*B)+C)

    To change the distance of revolution, change the first number A (shown as 10 at the moment); and to change the speed, change the number that's 1000 in the expression (B).

    https://dl.dropboxusercontent.com/u/14060718/rot l&R.gameproj.zip

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    @gyroscope

    Cheers for the credit gyroscope but the credit should really go to some old Greek fella from a couple of thousand - or so - years ago.

    One thing though, I've never really understood the inclusion of the modulus (in this case '%360') in pretty much every use of sin/cos you see in GameSalad, perhaps I'm not understanding it correctly, but from what I can see GameSalad is never going to run out of circle ! That's the nice thing about circles, they just keep going, same deal with self-time . . . . . ?

    For example the rotation in that example reads:
    (10*sin((self.Time*1000)%360))

    But it could simply be:
    10*sin(self.Time *1000)

    Unless I am being an idiot and overlooking something !?
    (In which case I deny all knowledge of this post).
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    Hi @Socks
    @gyroscope

    Cheers for the credit gyroscope but the credit should really go to some old Greek fella from a couple of thousand - or so - years ago.
    Ha, OK! You still get credit then for bringing it to the attention of the GS community, I reckon... :-)
    @gyroscope
    One thing though, I've never really understood the inclusion of the modulus (in this case '%360') in pretty much every use of sin/cos you see in GameSalad, perhaps I'm not understanding it correctly, but from what I can see GameSalad is never going to run out of circle ! That's the nice thing about circles, they just keep going, same deal with self-time . . . . . ?

    For example the rotation in that example reads:
    (10*sin((self.Time*1000)%360))

    But it could simply be:
    10*sin(self.Time *1000)

    Unless I am being an idiot and overlooking something !?
    (In which case I deny all knowledge of this post).
    Hey, I see what you mean... it works just fine without the modulus (so I can't see why its needed either so if you're being an idiot so am I!)

    One thing though, if you change the modulus figure (360) to something else less, you get a change in behaviour, so maybe it'll be useful once in a blue moon for someone...

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

  • hamzeyyyhamzeyyy Member Posts: 25
    Thanks a lot, I don't want it to move a lot in a wavey line just a bit. Guess I put 4sin instead of sin so it stretched the curve out?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    You're welcome. If you mean for it to go further around, one way and another, make the number larger, so try something like 20 or 25.... experiment until it's right for you. :-)

    P.S If you don't know - only change the numbers via the Expression Editor.

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    @gyroscope
    Hey, I see what you mean... it works just fine without the modulus (so I can't see why its needed either so if you're being an idiot so am I!)
    Join me in my stupidity, if we are both wrong I'll say it was your idea.
    One thing though, if you change the modulus figure (360) to something else less, you get a change in behaviour, so maybe it'll be useful once in a blue moon for someone...
    Sure, that make sense, if you impose a modulus on it (unnecessary in my opinion) and then set it to anything other than 360° you are going to screw up the circular/looping value of sin (or cos) - so for example using 330° instead of 360° will give you this (I've written this out as 5° increments because I am lazy) . . .


    . . . . 315° > 320° > 325° > 330° > 5° > 10° > 15° . . . . etc

    Instead of this:

    . . . . 345° > 350° > 355° > 360° > 5° > 10° > 15° . . . . etc

    Which means sin (or cos) doesn't get to loop properly, so there will be a jump/glitch.

    And yes, it's really useful for stuff like bounces . . . hold on I feel a demo coming up, back in a moment . . . .
  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    ...
  • SocksSocks London, UK.Member Posts: 12,822
    @gyroscope

    Here you go, I just abused your original file (ignore the Verge Logo, it was just the first image file to hand).
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    @gyroscope
    Hey, I see what you mean... it works just fine without the modulus (so I can't see why its needed either so if you're being an idiot so am I!)
    Join me in my stupidity, if we are both wrong I'll say it was your idea.
    :)) I can handle that... ;-)
    . . . . etc

    Which means sin (or cos) don't get to loop around a circle properly, so there will be a jump/glitch.

    And yes, it's really useful for stuff like bounces . . . hold on I feel a demo coming up, back in a moment . . . .
    Excellent, @Socks, I really like it. :-)

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

  • SocksSocks London, UK.Member Posts: 12,822
    @gyroscope
    I really like it.
    You can do the same deal with - for instance - a ball travelling in circle, limit its Y movement with %180 and you have a bounce - and if you switch off its X movement completely (hold down your mouse button in the example attached below) you have a perfect never ending bounce with a correctly dampened peak height and a hard transition when it hits the floor.

    In the below file the left circular movement has no % (or %360), the right circular movement has %180.

    Am I boring you yet, that's what I fully intend to do . . . . ;)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    ...Am I boring you yet, that's what I fully intend to do . . . . ;)
    Heh, sorry to disappoint you there, @Socks, I find your posts too entertaining to be bored by them... :-) B-)

    However your "boing" file did make my eyes go funny.... I shall be putting in an official complaint a.s.a.p. :P (It's good stuff again really, thanks!)

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

  • hamzeyyyhamzeyyy Member Posts: 25
    edited September 2013
    Really appreciate your help guys, I used the file that @gyroscope used and changed the 10sin to 7sin - less rotation and the time from 1000 to 800.

    I am having problems with alignment though, the actor starts off in the centre and end up towards the right, I need it to finish dead on in the centre, any help?

    I have tried using accelerate towards - positon 320 but it didn't help...


  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    Hi again, @hamzeyyy I had no problems with a test using Accelerate Towards. Maybe check the X position of your actor (best it's a whole number too) and confirm it matches exactly the X position in the behaviour.

    You can also use Interpolate instead if you wanted, on the actor's Y attribute, over a pre-determined time down to your base level Y position (without worrying about matching the x position).

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

  • joshiwujoshiwu Member Posts: 207
    that cool.
  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    Really appreciate your help guys, I used the file that @gyroscope used and changed the 10sin to 7sin - less rotation and the time from 1000 to 800.

    I am having problems with alignment though, the actor starts off in the centre and end up towards the right, I need it to finish dead on in the centre, any help?

    I have tried using accelerate towards - positon 320 but it didn't help...



    @hamzeyyy

    The problem is that your accelerate is set to 275°.

    Straight down is 270°.

    Your actor is behaving correctly given the rules shown in the video - and moving 5° off axis.

  • hamzeyyyhamzeyyy Member Posts: 25
    @socks ah yes! simple maths ey!! I did Maths A level too haha
  • hamzeyyyhamzeyyy Member Posts: 25
    It's weird how textbook maths is related to making an app, it's not easy maths too. How did you guys learn this stuff?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2013

    Here's the film trailer based on my earlier life to give you the idea of how I learnt:



    :))

    Seriously, with maths, apart from what I learnt from school, just checking out explanations on the internet (as long as its not too complicated...) :-)

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    It's weird how textbook maths is related to making an app, it's not easy maths too. How did you guys learn this stuff?
    Desperation : )

    This level of trigonometry is bizarrely simple, it looks complex, it sounds complex, it can achieve (relatively) complex things, but it really is simple - once you understand what sin(angle) actually does a whole world of wobbling, swinging, circling, rotating shaking, arcing, bouncing and spiralling things is all yours ! :)
  • SocksSocks London, UK.Member Posts: 12,822

    Here's the film trailer based on my earlier life to give you the idea of how I learnt:
    : )
Sign In or Register to comment.