Rotating from a specific angle in a pendulum like manner (using only one actor)

So for a game, I'm trying to make a swinging axe for something, and I'm trying to make to make it pivot from a single point. I know how to have something rotate from another point and around another actor, but is it possible to do this with only one actor and have it move like a pendulum? This is what I'm trying to achieve (only a little smoother :P): photo DeathAxeAnimation_zpsa274af35.gif

Having trouble with your game? Sounds like a personal problem.

Comments

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

    Yeah, that's pretty straightforward, you just need to rotate the actor around a point using sine and cosine, but make the angle they both operate on a sine wave, hope that makes sense.

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

    Example, if your actor is 160 pixels tall . . . .

    Constrain X position to: 80*cos((range of swing in degrees*sin( self.Time *speed of swing))-90)+pivot point X
    
    Constrain Y position to: 80*sin ((range of swing in degrees*sin( self.Time *speed of swing))-90)+pivot point Y 
    
    Constrain rotation to: range of swing in degrees*sin( self.Time *speed of swing))
    
  • SocksSocks London, UK.Member Posts: 12,822

    Hold on, this is getting messy, let me make a demo project . . . . . back in a minute. . .

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

    I actually was able to figure it out fine, but thanks! It helped a TON. Quick question though, does the 80 in the expression state the pivot location? Because I changed it from 80 to 96 since it wasn't pivoting around the the end of the rod and then it pivoted around it fine.

    Having trouble with your game? Sounds like a personal problem.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @ADSentertainment‌ -- I like @Socks way of making a pendulum animation. (And I prefer to do it that way.) But just for kicks, here is another real fun way of making an actor swing like a pendulum.

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

    @ADSentertainment said:
    I actually was able to figure it out fine, but thanks! It helped a TON. Quick question though, does the 80 in the expression state the pivot location? Because I changed it from 80 to 96 since it wasn't pivoting around the the end of the rod and then it pivoted around it fine.

    80 was simply half the height (the radius) of my example size ("Example, if your actor is 160 pixels tall. . . "). So you could say the 80 states the pivot point.

    So, if 96 worked for your particular actor, I guess your actor was 192 pixels tall ?

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

    @RThurman said:
    ADSentertainment‌ -- I like Socks way of making a pendulum animation. (And I prefer to do it that way.) But just for kicks, here is another real fun way of making an actor swing like a pendulum.

    I can't look at the attachment as I'm not at my real computer right now, but I am going to guess that coming from you it involves some fiendishly clever maths !

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Socks said:
    I can't look at the attachment as I'm not at my real computer right now, but I am going to guess that coming from you it involves some fiendishly clever maths !

    Thanks! It does use radians (converted to degrees) but hopefully everything is straightforward enough to be useable. Its mathematically equivalent to your suggestion. It just uses the move behavior to reposition the actor's x,y coordinates -- rather than using two constrain x,y behaviors.

  • ADSentertainmentADSentertainment Member Posts: 397

    @Socks said:
    So, if 96 worked for your particular actor, I guess your actor was 192 pixels tall ?

    Precisely. That's what I meant to say :p

    Having trouble with your game? Sounds like a personal problem.

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

    @RThurman said:
    Thanks! It does use radians (converted to degrees) but hopefully everything is straightforward enough to be useable. Its mathematically equivalent to your suggestion. It just uses the move behavior to reposition the actor's x,y coordinates -- rather than using two constrain x,y behaviors.

    Just taken a look . . . . scary stuff ! : ) Really neat, but scary nonetheless.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @RThurman‌ and @Socks‌

    I bow to you gentlemen. Fantastic stuff as usual.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Socks‌ and @Braydon_SFX‌ -- I swear its GameSalad! Its just a fantastic tool to work with!

  • shylevarishylevari Member Posts: 16

    @RThurman‌ nice file man :)
    what to do in order to change speed, swing range, and starting angle?

    for example:
    make the axe swing in a smaller arch, closer to the floor

  • meynardmeynard Member Posts: 2

    Hi guys,

    How do you make it to swing starting from the left to the middle and then vice versa?

    Thanks

  • meynardmeynard Member Posts: 2

    only swinging halfway than the script you guys gave.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2015

    @meynard said:
    Hi guys,

    How do you make it to swing starting from the left to the middle and then vice versa?

    Thanks

    Constrain X to 98 *cos((45 *sin( self.Time *160))-135)+512
    Constrain Y to 98 *sin((45 *sin( self.Time *160))-135)+384
    Constrain Rotation to 45 *sin( self.Time *160)-45

Sign In or Register to comment.