Make Object Swing back and forth like Pendulum
butterbean
Member Posts: 4,315
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?
Comments
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+)
_______________________
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.
Edit: Just opened up CodeMonkey's Example Rotations and there was self.Time. I bet everybody knew about it but me...
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?
lol
Okay, I'm not getting A3MG method to work. Butterbean, did you?
So what am I missing? Where is the motion coming in? I've tried using this exactly and nothing is happening.
</dense mode>
Hang On (Demo)
Cheers!
I can't dig into it until tomorrow, but I think that will do what I need.
Out of curiosity, is it possible to make a pendulum slow down and stop?
Edit: Oh, and we would have to decrease the '160' and '40' amounts (the length of the arc) as well.
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.
Hang On 2 (Demo)
I'll also e-mail you a copy.
Cheers.
Cheers.
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!