Swinging Pendulum

Started by supermystery, April 21, 2009, 10:15:39 PM

Previous topic - Next topic

supermystery

How would i get something like this to swing back and forth like a pendulum in mugen?



Any help is appreciated

PotS

Axis on top, angledraw with a cos/sin expression in its value.
You can help with Ikemen GO's development by trying out the latest development build and reporting any bugs on GitHub.
My Mugen and Ikemen content can also be found here.

Bastard Mami

QuoteA pendulum is a weight suspended from a pivot so it can swing freely.[1]

When a pendulum is displaced from its resting equilibrium position, it is subject to a restoring force due to gravity that will accelerate it back toward the equilibrium position. When released, the restoring force will cause it to oscillate about the equilibrium position, swinging back and forth. The time for one complete cycle, a left swing and a right swing, is called the period. From its discovery around 1602 by Galileo Galilei the regular motion of pendulums was used for timekeeping, and was the world's most accurate timekeeping technology until the 1930s.[2] Pendulums are used to regulate pendulum clocks, and are used in scientific instruments such as accelerometers and seismometers. Historically they were used as gravimeters to measure the acceleration of gravity in geophysical surveys, and even as a standard of length. The word 'pendulum' is new Latin, from the Latin pendulus, meaning 'hanging'.[3]

QuoteThe simple gravity pendulum[4] is an idealized mathematical model of a pendulum.[5] [6] [7] This is a weight (or bob) on the end of a massless cord suspended from a pivot, without friction. When given an initial push, it will swing back and forth at a constant amplitude. Real pendulums are subject to friction and air drag, so the amplitude of their swings declines.



http://en.wikipedia.org/wiki/Pendulum

so yeah, better use pots' method.

Marioman19

Oh god.

You're making wrecking ball Robotnik, aren't y- *shot*

supermystery

Would of been nice to see some coding examples, in any case thanks for the advice :yes:

Quote from: Marioman19 on April 21, 2009, 10:57:55 PM
Oh god.

You're making wrecking ball Robotnik, aren't y- *shot*

:-X

Havent decided yet, it all depends on if i can get the swinging thing to work   ;P

MikeDaBike

Use this for your AngleDraw controller:
A*sin(Time*Pi/T)
A is the angle that the pendulum swings (in degrees).
T is the half cycle duration (in GameTicks).

Example:
45*sin(Time*Pi/120)
Try this to make the pendulum swing halfway up and down every 4 seconds.

Quote from: Brokenpots HD on April 21, 2009, 10:20:46 PM
Axis on top
Dont forget this.
Latest Creation: SSBB Assist Trophies

supermystery

Thank you very much MikeDaBike, now i have something to work with :yes:

supermystery

I have another question, is it possible to use a velset to make a helper move like a pendulm without using angledraw?

Any help is appreciated

Bastard Mami

obviously yes, that's the preferred method as angledraw does not affect the clsns.

Ricepigeon

Quote from: Konata~ on April 23, 2009, 11:24:06 PM
obviously yes, that's the preferred method as angledraw does not affect the clsns.

You would still need to use angledraw, but the pendulum would exist as two separate helpers: the bob, which contains your clsn boxes which you'll be using the velsets on, and the cord, which you'll be applying the Angledraw to and has no clsn boxes.

supermystery

Yep your right angledraw would be alright for the chain just not for the ball

Yeah heres the problem:



Would this code make the ball constantly move like a pendulum?

[State, 9000]
type = velset
trigger1 = time = 0
x = -90*cos(Time*Pi/300)
y = -10*cos(Time*Pi/300)

Also how would bindtoparent work with it so it doesnt go flying away from its parent?

Anjel

The chain is the balls parent?
If so, try to bind the ball to the chain using the same attributes as the chain's angledraw.
My shitty mugen stuff:

supermystery

Just tried it

Doing that makes the chain swing ok but the ball doesnt swing the same way as the chain does also the clsn doesnt stay with the ball as it moves.

MikeDaBike

Quote from: supermystery on April 24, 2009, 10:33:42 AM
Would this code make the ball constantly move like a pendulum?

[State, 9000]
type = velset
trigger1 = time = 0
x = -90*cos(Time*Pi/300)
y = -10*cos(Time*Pi/300)

This should work, only problem here is that you use way to high values. A velocity of 90 is pretty fast. Try using small values like 2 or 3. Also the y-vel should use only negative values to make it symmetric.

Then it should look something like this:
x = -4*cos(Time*Pi/300)
y = -2*abs(cos(Time*Pi/300))

Latest Creation: SSBB Assist Trophies

supermystery

Quote from: MikeDaBike on April 24, 2009, 12:25:55 PM
Quote from: supermystery on April 24, 2009, 10:33:42 AM
Would this code make the ball constantly move like a pendulum?

[State, 9000]
type = velset
trigger1 = time = 0
x = -90*cos(Time*Pi/300)
y = -10*cos(Time*Pi/300)

This should work, only problem here is that you use way to high values. A velocity of 90 is pretty fast. Try using small values like 2 or 3. Also the y-vel should use only negative values to make it symmetric.

Then it should look something like this:
x = -4*cos(Time*Pi/300)
y = -2*abs(cos(Time*Pi/300))



It still seems to move in the wrong direction also it cant really be used with bind to parent which is necessary for this, otherwise it will just rotate in same place and not follow the character

Thanks for trying though, i guess this really is tougher than i thought.

MikeDaBike

Another thought:
Make an anim in your air file for the ball movement instead of calculating its movement. This way you can make perfect clsn1 alignment and bindtoparent is also possible. Problem though is that the movement might not look that good unless you use alot of animation elements.
Latest Creation: SSBB Assist Trophies

supermystery

Darn, i was hoping that wouldnt be the case

oh well

thanks for your help :yes:

Bastard Mami

first try to get the pendulum movement right, then add the binding.

let's work out the pendulum move of a helper related to a static place, while sin and cos might be innacurate they can get the job done efficiently and the innacuracies might be too small to be a matter.


MikeDaBike

I dont know if you are still on it, but the code I posted for the vel is wrong.
This would work if you are still interested:
x = -1*cos(Time*Pi/300)
y = -1*sin(Time*Pi/150)
For greater distances or slower movement, change the values (the sin time multiplier has to be the half of the cos time multiplier)

The problem here is that BindToParent wont work, you got to simulate it with posadd, which is complicated and wont work without an extra helper.

The probably simplest way to deal with it, is to directly bind the ball to the right position:
[State 0, BindToParent]
type = BindToParent
trigger1 = 1
pos = 50*sin(Time*Pi/300),50*abs(cos(Time*Pi/300))
You can even specify the exact X/Y distance.

Sorry if you already made a complete animation like I suggested before.
Latest Creation: SSBB Assist Trophies

supermystery

Nah i didnt bother trying to do a complete animation, i knew it would look bad.

that bind for the actual ball works perfectly, thanks. The only problem is that it seems to flip everytime the main character turns round even when using the noautoturn assert special in its actual state. 

Also for some reason i cant get the chain and the ball to move at the same time.

code:

Chain

;---------------------------------------------------------------------------
; Swinging Ball Rings
[Statedef 1050]
type    = A
movetype= A
physics = N
juggle  = 4
poweradd= 110
;velset = 0,0
anim = 640
ctrl = 0
sprpriority = -2

[State 0, BindToParent]
type =BindToParent
trigger1 = 1
pos = 0,-107 ;Because axis is on top
;facing = 0
time = -1

[State -1, WideOpen]
type = AssertSpecial
trigger1 = 1
flag = noautoturn

[State 210, 3] ;Chain animation
type = ChangeAnim
trigger1 = anim != 613
trigger1 = parent,stateno = 0
value = 613

[State 0, ]
type =AngleDraw
trigger1 = 1
value = 100*cos(Time*Pi/200)

[State 1050, 5]
type = DestroySelf
trigger1 = parent,stateno = 5150


Ball:

;---------------------------------------------------------------------------
; Swinging Ball 2
[Statedef 1051]
type    = A
movetype= A
physics = N
juggle  = 4
;velset = 0,0
anim = 640
ctrl = 0
sprpriority = -2

[State -1, WideOpen]
type = AssertSpecial
trigger1 = 1
flag = noautoturn

[State 0, BindToParent]
type =BindToRoot
trigger1 = 1
pos = 100*sin(Time*Pi/200),100*abs(cos(Time*Pi/200))
;facing = 0
time = -1

[State 210, 3];Ball Animation
type = ChangeAnim
trigger1 = anim != 608
trigger1 = root,stateno = 0
value = 608

[State 1050, 4]
type = null;HitDef
trigger1 = Time = 0
attr = A, SA
animtype  = Medium
damage    = 80, 4
priority  = 5
guardflag = MA
pausetime = 12,12
sparkxy = -10,-70
hitsound   = 5,3
guardsound = 6,0
ground.type = Low
ground.slidetime = 20
ground.hittime  = 20
ground.velocity = -3.5,-7
guard.velocity = -7
air.velocity = -3.5,-7
fall = 1

[State 1050, 5]
type = DestroySelf
trigger1 = root,stateno = 5150

;---------------------------------------------------


Anyway the bindtoparent/root things works great for the ball, thanks for your help.