YesNoOk
avatar

Swinging Pendulum (Read 1536 times)

Started by supermystery, April 21, 2009, 10:15:39 pm
Share this topic:
Swinging Pendulum
#1  April 21, 2009, 10:15:39 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
How would i get something like this to swing back and forth like a pendulum in mugen?



Any help is appreciated
Re: Swinging Pendulum
#2  April 21, 2009, 10:20:46 pm
  • ******
    • www.mugenguild.com/pots/
Axis on top, angledraw with a cos/sin expression in its value.
Use anything you want from my works.  If you need to contact me use email, not private messages.
Re: Swinging Pendulum
#3  April 21, 2009, 10:46:20 pm
  • ******
  • [E]
    • Mexico

  • Online
Quote
A 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]

Quote
The 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.
Re: Swinging Pendulum
#4  April 21, 2009, 10:57:55 pm
  • **
  • Edit coming soon?
Oh god.

You're making wrecking ball Robotnik, aren't y- *shot*
Re: Swinging Pendulum
#5  April 22, 2009, 11:59:23 am
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
Would of been nice to see some coding examples, in any case thanks for the advice :yes:

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
Re: Swinging Pendulum
#6  April 22, 2009, 12:50:54 pm
  • **
Use this for your AngleDraw controller:
[mcode]A*sin(Time*Pi/T)[/mcode]
A is the angle that the pendulum swings (in degrees).
T is the half cycle duration (in GameTicks).

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

Axis on top
Dont forget this.
Latest Creation: SSBB Assist Trophies
Re: Swinging Pendulum
#7  April 22, 2009, 03:40:51 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
Thank you very much MikeDaBike, now i have something to work with :yes:
Re: Swinging Pendulum
#8  April 23, 2009, 09:10:49 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
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
Re: Swinging Pendulum
#9  April 23, 2009, 11:24:06 pm
  • ******
  • [E]
    • Mexico

  • Online
obviously yes, that's the preferred method as angledraw does not affect the clsns.
Re: Swinging Pendulum
#10  April 24, 2009, 02:08:23 am
  • *****
  • Mega Klinklang confirmed
    • USA
    • ricepigeon.webs.com
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.

<<-- Updated 09/14/14

You limit yourself so badly when you try to avoid variables. When you get over your fear of the "complexity" of variables, you will find yourself in a better place: A beautiful world where coding is actually fun.
Re: Swinging Pendulum
#11  April 24, 2009, 10:33:42 am
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
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?
Re: Swinging Pendulum
#12  April 24, 2009, 10:40:02 am
  • *****
    • Mexico
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.
Re: Swinging Pendulum
#13  April 24, 2009, 11:00:23 am
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
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.
Re: Swinging Pendulum
#14  April 24, 2009, 12:25:55 pm
  • **
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
Re: Swinging Pendulum
#15  April 24, 2009, 12:46:48 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
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.
Re: Swinging Pendulum
#16  April 24, 2009, 04:26:52 pm
  • **
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
Re: Swinging Pendulum
#17  April 24, 2009, 05:09:01 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
Darn, i was hoping that wouldnt be the case

oh well

thanks for your help :yes:
Re: Swinging Pendulum
#18  April 24, 2009, 06:11:47 pm
  • ******
  • [E]
    • Mexico

  • Online
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.

Re: Swinging Pendulum
#19  April 26, 2009, 12:04:13 am
  • **
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:
[mcode]x = -1*cos(Time*Pi/300)
y = -1*sin(Time*Pi/150)[/mcode]
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:
[mcode][State 0, BindToParent]
type = BindToParent
trigger1 = 1
pos = 50*sin(Time*Pi/300),50*abs(cos(Time*Pi/300))[/mcode]
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
Re: Swinging Pendulum
#20  April 26, 2009, 09:25:25 am
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
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

Code:
;---------------------------------------------------------------------------
; 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:

Code:
;---------------------------------------------------------------------------
; 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.
Re: Swinging Pendulum
#21  April 26, 2009, 04:05:07 pm
  • **
Ok, for the turning issue you got to make the x-binding dependent on the chars facing:
[mcode]pos = 100*sin(Time*Pi/200)*root,facing,100*abs(cos(Time*Pi/200))[/mcode]

To make the ball and chain almost the same movement you got to tweak the values. I would recommend to let your ball anim just consist of the clsn1 box, and then tweak the binding to make it follow the ball and chain anim as good as possible.
Latest Creation: SSBB Assist Trophies
Re: Swinging Pendulum
#22  April 26, 2009, 07:55:43 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
Works very well  :), i decided not to bother with the angeldraw method with the chain and i just created more helpers (the 4 small hoops) that bind in the same way as the ball



The one thing that i noticed though is sometimes when the ball reaches its highest point it flickers a bit from to side before it gets in position again, this only happens when robotnik is turning though.
Re: Swinging Pendulum
#23  April 26, 2009, 08:47:17 pm
  • **
The one thing that i noticed though is sometimes when the ball reaches its highest point it flickers a bit from to side before it gets in position again, this only happens when robotnik is turning though.

Hmm when I tested this nothing like that ever happened. Does this maybe happen when you hit the opponent? Ignorehitpause=1 may help then.
Otherwise you got to go more into detail what happens and when.
Latest Creation: SSBB Assist Trophies
Re: Swinging Pendulum
#24  April 26, 2009, 09:19:30 pm
  • avatar
  • ***
    • www.angelfire.com/moon2/ned
hitpauses have no effect, it happens randomly when the character turns, instead of going back the way it came by going back down again, it just instantly goes to the position without following itself back to that spot. Hard to explain im afraid, its not too noticable its just kinda wierd when it does happen.

Ill give you the link, to see what i mean. the helpers that swing are in Attack.cns

states are 1050 and 1051