Make Object Swing back and forth like Pendulum

butterbeanbutterbean Member Posts: 4,315
edited November -1 in Working with GS (Mac)
What would be the best way to achieve rotating an object as if it's swinging like a pendulum to the left and right, almost like an object hanging from a balloon?
«1

Comments

  • KamazarKamazar Member Posts: 287
    Good ol' parabola and algebra 2. Too bad I don't remember much from it, and it hasn't even been a year yet. Ok, equation: (y - k)^2 = -4a(x - h). The negative is to flip it over, otherwise, it'd be an arc instead of the path of a pendulum. H and K are the x and y coordinates respectively. You don't have to enter anything for the actual X and Y in the equation. The "a" will determine the width of parabola, fractions make it thinner, whole numbers wider. I might be wrong about a couple things. Second set of eyes to look over this would be great. Mind you, once you have the parabola down, you're gonna have to find a way for it to swing one direction, stop, then the next. I'm thinking a timer function? ... yeah, so, fun, right? Right?
  • synthesissynthesis Member Posts: 1,693
    I would think you could just interpolate the rotation attribute around its center point between a high and low value...such as 220 to 320. But the actor would need to be twice as big...to allow the pivot point of the graphic to be the center point...not an end point. Just make the extra actor space transparent above the pivot/center point.

    I've never actually done this...but it seems like it would work in theory.

    _______________________

    *** visit www.spiritApps.com to check out the Spirit Connoisseur Apps ***
    (Rum and Vodka now available for 17+)
    _______________________
  • FranzKellerFranzKeller Member Posts: 517
    Yes that's likely to work
  • A3MGA3MG Member Posts: 152
    For landscape where it is swinging through the center

    Constrain Attribute: self.Position.X To: 160*cos(self.Time*200%360)+240
    Constrain Attribute: self.Position.Y To: 40*cos((self.Time*400%360)+160
    Constrain Attribute: self.Rotation To: vectorToAngle(240-self.Position.X,160-self.Position.Y)+90

    160*cos determines the swing amount back and forth
    40*cos determines the up and down amount

    200 and 400 are the speed (I had to play around with these to make it work - for a little fund make them different amounts and see what happens)
    +240 and +160 makes the center point of the screen (want it lower, make the +160 just +60 or something)

    The +90 on the rotate is an offset for me to make my object be rotated how I wanted it.
  • JackBQuickJackBQuick Member Posts: 524
    @A3MG - Very nice work. I like how you used self.Time in the formulas -- I've never seen that done before but it works great!

    Edit: Just opened up CodeMonkey's Example Rotations and there was self.Time. I bet everybody knew about it but me...
  • butterbeanbutterbean Member Posts: 4,315
    Wow.... beyond my scope, but nice work A3MG :)

    Now the trick is, how do I get the girl to grab onto the end of the rope and swing back and forth? And when she pushes jump, to let go?
  • A3MGA3MG Member Posts: 152
    A rope huh, like pitfall. Hmmmm.
  • AfterBurnettAfterBurnett Member Posts: 3,474
    butterbean said:
    Wow.... beyond my scope, but nice work A3MG :)

    Now the trick is, how do I get the girl to grab onto the end of the rope and swing back and forth? And when she pushes jump, to let go?

    How do I get her to grab something else?
  • ORBZORBZ Member Posts: 1,304
    spawn actor to switch between Swinging Girl and Walking Girl
  • butterbeanbutterbean Member Posts: 4,315
    @OrbZ: But how do I get her to grab onto the rope in the first place? Do I constrain her to the bottom of the rope somehow?
  • design219design219 Member Posts: 2,273
    POLYGAMe said:
    How do I get her to grab something else?

    groan.
  • design219design219 Member Posts: 2,273
    ORBZ said:
    spawn actor to switch between Swinging Girl and Walking Girl

    double groan.

    lol

    Okay, I'm not getting A3MG method to work. Butterbean, did you?
  • design219design219 Member Posts: 2,273
    A3MG said:
    For landscape where it is swinging through the center

    Constrain Attribute: self.Position.X To: 160*cos(self.Time*200%360)+240
    Constrain Attribute: self.Position.Y To: 40*cos((self.Time*400%360)+160
    Constrain Attribute: self.Rotation To: vectorToAngle(240-self.Position.X,160-self.Position.Y)+90

    160*cos determines the swing amount back and forth
    40*cos determines the up and down amount

    200 and 400 are the speed (I had to play around with these to make it work - for a little fund make them different amounts and see what happens)
    +240 and +160 makes the center point of the screen (want it lower, make the +160 just +60 or something)

    The +90 on the rotate is an offset for me to make my object be rotated how I wanted it.

    <dense mode>
    So what am I missing? Where is the motion coming in? I've tried using this exactly and nothing is happening.
    </dense mode>
  • JackBQuickJackBQuick Member Posts: 524
    Perhaps this might help clear up some things:

    Hang On (Demo)

    Cheers!
  • design219design219 Member Posts: 2,273
    That looks most excellent. Thank YOU!!!

    I can't dig into it until tomorrow, but I think that will do what I need.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    That's awesome!
  • design219design219 Member Posts: 2,273
    Okay, being dense again, but how do I download this project? I tried the "download project" button, but I'm getting a chess board image.
  • JackBQuickJackBQuick Member Posts: 524
    The download project button should have done it but I'll e-mail the project to you when I get home tonight.
  • design219design219 Member Posts: 2,273
    Thank you sir! My address is billcox (at) ksdweb.com.

    Out of curiosity, is it possible to make a pendulum slow down and stop?
  • JackBQuickJackBQuick Member Posts: 524
    @design219 - Yes, it's possible to make the pendulum slow down and stop. The '200' and '400' in A3MG's original equations represent the speeds. If you replace it with an attribute that decreases over time, I think this effect can be achieved. I'll try it out before I e-mail you the project -- probably in six to eight hours from now.

    Edit: Oh, and we would have to decrease the '160' and '40' amounts (the length of the arc) as well.
  • design219design219 Member Posts: 2,273
    Jack... you rock man!
  • JackBQuickJackBQuick Member Posts: 524
    @design219 - I just sent you an e-mail with two files attached: the original one, and one where the arm of the pendulum has been added and the pendulum slows down.

    I couldn't get the newer version to work smoothly, I'm afraid. I'm sure that there's a better way to achieve the effect you want; however, at this point, I don't know what it is.
  • JackBQuickJackBQuick Member Posts: 524
    @design219 - Just sent you a better working copy. Still not happy with it but it'll get you closer to what you want :)
  • JackBQuickJackBQuick Member Posts: 524
    @design219 - I've just published a final version of the demo with the modification you asked for (i.e. that the pendulum slows down to a stop):

    Hang On 2 (Demo)

    I'll also e-mail you a copy.

    Cheers.
  • EdwardRHunterEdwardRHunter Member Posts: 7
    This was awesome, very helpful. I know I'm revealing just how awful at math I really am, but how would I apply this to make an actor move around in a circle? I'm trying to get an actor to move in a circle around another object but it is eluding me as to how. This looks promising but after monkeying with it for quite a while I cant make it work how I want it to.

    Cheers.
  • JackBQuickJackBQuick Member Posts: 524
    @EdwardRHunter - CodeMonkey has an excellent demo here that addresses your question:

    Example Rotations

    Look at the behaviours in his Orbital actor where he constrains the x-coordinate of Orbital to:

    60*cos( self.Time *300%360)+ game.TankXPosition

    and its y-coordinate to:

    60*sin( self.Time *300%360)+ game.TankYPosition

    In these equations:

    60 represents the radius of the circle (in pixels).

    self.Time *300%360 is the angle. Here, it increments itself (because it's tied to the time) through 360º of a circle.

    game.TankXPosition and game.TankYPosition are the x- and y-coordinates of the object it is circling.

    I hope this helps. Cheers!
  • A3MGA3MG Member Posts: 152
    @JackBQuick - nice work on the demos!
  • EdwardRHunterEdwardRHunter Member Posts: 7
    This definitely helps, thanks much!
  • DimensionGamesDimensionGames PRO Posts: 993
    JackBQuick said:
    @EdwardRHunter - CodeMonkey has an excellent demo here that addresses your question:

    Example Rotations

    Look at the behaviours in his Orbital actor where he constrains the x-coordinate of Orbital to:

    60*cos( self.Time *300%360)+ game.TankXPosition

    and its y-coordinate to:

    60*sin( self.Time *300%360)+ game.TankYPosition

    In these equations:

    60 represents the radius of the circle (in pixels).

    self.Time *300%360 is the angle. Here, it increments itself (because it's tied to the time) through 360º of a circle.

    game.TankXPosition and game.TankYPosition are the x- and y-coordinates of the object it is circling.

    I hope this helps. Cheers!

    Im also trying to do the same things as EdwardRHunter but unlike him I have no clue what that means what I should do! How would I implement these rules? Sorry for asking a stupid question there!
  • DimensionGamesDimensionGames PRO Posts: 993
    BUMP.
Sign In or Register to comment.