Still stuck on making a good pendulum...

NtGNtG Member Posts: 103
edited December 2011 in Working with GS (Mac)
Hi, so the main part of my game involves a pendulum and i've looked through the pendulum and swinging demos but im still stuck on getting the pendulum to look normal rather than robotic. I want it to look like the pendulum here: http://myphysicslab.com/pendulum1.html but all of the demos i have seen just look to robotic like the pendulum doesn't slow down at it's peak. Any help would be appreciated.

I've posted similar discussions about 4 times, but i keep changing how i want the pendulum to act, and have never got it to work exactly how i would like.

Also, I looked for fire maple's hanging/swinging demo again, but cant find it.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Here is an example of a pendulum using vertlet integration. (Don't tell anyone, but if you string a bunch of these together you get a rope/chain. The catch is, too many 'joints' and it really slows down an older device.)

    http://speedy.sh/PqFjN/PendulumOrRope-2.zip

    RThurman
  • NtGNtG Member Posts: 103
    That looks real nice, how could i put an actor at the end of the rope? and do you know how to make it so it doesn't slow down?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited December 2011
    @NtGsaid:
    That looks real nice, how could i put an actor at the end of the rope? and do you know how to make it so it doesn't slow down?
    OK -- I see what you are looking for. You don't want it to slow down due to gravity. You want it to slow down as it reaches its peak and reverses direction. (But to never stop.) That actually simplifies things considerably. Here is an example you can explore. It has a pivot point (nail), a rod, and a bob at the end of the rod.

    http://speedy.sh/S7wVb/simplePendulum.zip

    Hope this helps!
    RThurman
  • NtGNtG Member Posts: 103
    edited December 2011
    Wow, thanks RThurman! that is exactly what i am looking for! One question: What would i need to change to make it move a little bit faster?
  • NtGNtG Member Posts: 103
    Nevermind, a more negative gravity value did the trick.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited December 2011
    Glad it works for you. Rather than messing with gravity to make it 'faster', you can multiply the acceleration. Try modifying the first behavior inside the timer like this:

    Change Attribute: game.acceleration To: 10*( game.gravity/game.rodLength*sin(game.pendulumAangle ))

    Here, I am multiplying the original equation by "10". (But but you can use any multiplier. Whatever feels about right.)

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @Tshirt
    Thanks for the background info about angular velocity. That explains a few things for me!

    One way to figure out the fps would be the following:
    Timer (every 0 seconds)
    ----Change Attribute self.myCounter To: self.myCounter +1

    Timer (every 1 seconds)
    ----Change Attribute self.myFPS To: 2*self.myCounter
    ----Change Attribute self.myCounter To: 0

    Display Text: self.myFPS

    While it might not be completely accurate (my tests showed it could be off by as much as 2 fps), it might work for your purposes.

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @tshirtboothsaid:
    Yours is almost what we had but as you know yours will not collide with other actors.:(
    fingers crossed we get joints soon. this will make things a lot better
    But Tshirt -- you have already shown how to get around the collision issue. You showed that you could use velocity and acceleration to get objects to follow the mouse while at the same time collide with other objects. Its just a simple extrapolation to do it with angles. Here is an example of a chain (of multiple pendulums) that interacts with (collides with) other objects. Its based almost entirely on the principle you showed how to do!

    http://speedy.sh/v28ar/YetAnotherChain.zip
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    OK!
    By the way - I do agree with you about joints. While they are possible to do in GS -- having access to box2D joints will make all this so much easier!

    RThurman
  • NtGNtG Member Posts: 103
    Hey, one last question (hopefully lol). Do you have any projects where it's like the reverse of your first one in that the more it swings, the higher it goes (as if someone is swinging on a swing set)?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @NtG -- you can get the pendulum to swing higher by multiplying velocity by a very small increment. Modify the second behavior in the timer block like this:

    Change Attribute: game.velocity To: 1.001*(game.velocity+game.acceleration)

    You can experiment with the '1.001' to get different rates of change.

    Hope this helps
    RThurman
  • NtGNtG Member Posts: 103
    Nice! Your help is greatly appreciated! I can finally get my level designing underway.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    You are welcome! Glad it works for you.
    RThurman
  • NtGNtG Member Posts: 103
    edited December 2011
    Turns out that wasn't my last question, but this should do it... How do you do the first example, but with the bob where it slows down.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    You are gonna love this! Just change the same velocity behavior like this:
    Change Attribute: game.velocity To: .99*(game.velocity+game.acceleration)

    Anything above 1.0 and velocity swings it higher. Anything below 1.0 and it swings lower. (And of course exactly 1.0 puts it in perpetual motion.)

    RThurman
  • buddhabratabuddhabrata Member Posts: 2

    @RThurman said:
    Here is an example of a pendulum using vertlet integration. (Don't tell anyone, but if you string a bunch of these together you get a rope/chain. The catch is, too many 'joints' and it really slows down an older device.)

    http://speedy.sh/PqFjN/PendulumOrRope-2.zip

    RThurman

    Hi, could you please share this again, the link seems to have expired. I am trying to do a swing pendulum motion too.

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

    I think that file is lost. Here is another one that might work for you.
    http://www.mediafire.com/download/e3zg477cekl764j/simplePendulum.zip

  • buddhabratabuddhabrata Member Posts: 2

    thank you very much :smiley:

    also, i was hoping to make it look like a chain of links is attached to the nail, so looking for a kind of a wavy (rope like) effect on the rod while it swings :smile:

Sign In or Register to comment.