Rotate to angle

afula86afula86 Member, PRO Posts: 9
edited August 2014 in Working with GS (Mac)

Hi guys,
I'm trying to do a pretty simple thing and I'll appreciate your help.
I have an object, looks like a stick lets say: |
I'm trying to rotate it in a loop to angle 40 and then to 320 and so on in a loop- like swinging.
the object starts with rotation = 40.
What I did is to use the "Rotate to Angle" behaviour. I ask if self.Rotation between 40-45, then rotate to angle 320. if rotation between 320-325 then rotate to angle 40.
What happens is that it really goes to angle 320 for the first time and then goes back to angle 40 as it suppose to but thats it! it doesnt do it in a loop! Only one swing to the left and one to the right. I've tried to play with the "run to completion" "stops on destination" buttoms but no luck...
How do I make it swing in a loop???

Thanks,
Stas.

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2014

    You can do it with a couple of constrains . . . . . actually three if you throw one in for rotation.

    Constrain the x position to A*cos(B*sin(self.Time*C))+D
    Constrain the y position to A*sin(B*sin(self.Time*C))+E
    And constrain the rotation to B*sin(self.Time*C)
    


    A = half the length of your stick

    B = the number of degrees you want it to swing from 0° (both up and down)

    C = speed of the swing

    D = horizontal position of the stick

    E = vertical position of the stick.

    Hold on, I'll do a quick example . . .

  • SocksSocks London, UK.Member Posts: 12,822

  • afula86afula86 Member, PRO Posts: 9

    Thanks for the detailed answer!
    And do you know how would this swinging stick move down lets say?
    I mean, moving down while swinging (the Y is changing always)

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2014

    @afula86 said:
    Thanks for the detailed answer!
    And do you know how would this swinging stick move down lets say?
    I mean, moving down while swinging (the Y is changing always)

    I posted the various parameters in my post above . . . .

    E = vertical position of the stick

  • AlkaPPAlkaPP Member, PRO Posts: 194

    @socks do you have the demo file to share???

    My Gamesalad Games On App Store:

    Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2014

    @AlkaPP said:
    socks do you have the demo file to share???

    I don't think I saved the project from the video, but it's simple enough to do yourself, just follow the instructions above, place three constrain behaviours on your actor and adjust the values to suit your needs.

  • SocksSocks London, UK.Member Posts: 12,822

    @AlkaPP said:
    socks do you have the demo file to share???

    EDIT: demo file . . . . .

    https://www.mediafire.com/?azlqyl45jt5fya4

  • AlkaPPAlkaPP Member, PRO Posts: 194

    Thanks @socks i did try myself. it turn out not swinging but weird rotating result. Thanks for the file :)

    My Gamesalad Games On App Store:

    Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1

Sign In or Register to comment.