Make an actor swing (not accelerate towards)? ADVANCED HELP NEEDED

NtGNtG Member Posts: 103
edited November -1 in Working with GS (Mac)
How would i go about getting an actor to throw a rope and swing at a fixed radius around an object? Not like Swing Knight where he accelerates towards the object i would like the rope to maintain the same length while keeping the actor on the end. I know there is probably some trig/algebra involved, but i cant seem to get it right (and I got a 4 on my AP calc test, so i know my math). Or could i make this happen with the magnitude function?

Say:

if ropethrown=true
change attribute "distance" to magnitude(abs(blockX-actorX),abs(blockY-actorY))
then inside that put this:
if distance ≠ 80
move actor to distance 80 away from object???? (dont know how i would do that)

I would also like for the movement to a certain distance away from the block to be smooth.
Can anyone help at all? I've looked at all of these pendulum and arc/swing templates and i just cant get this work. ANY help would be appreciated.

Comments

  • wormilwormil Member Posts: 127
    There is a demo of this in the demos...
    swing knight
  • wormilwormil Member Posts: 127
    Oh. Right. He wants a castlevania swing. that's going to be an arc based on circle, like a pendulum. I'd look up the 2d physics motion for a pendulum and implement that.

    Swing Knight is much better ;-P
  • LumpAppsLumpApps Member Posts: 2,881
    There also is another example in the demos from fire maple games.
    I believe you find it when you search for Swing.
  • NtGNtG Member Posts: 103
    LudwigHeijden said:
    There also is another example in the demos from fire maple games.
    I believe you find it when you search for Swing.

    I looked at that and there is no code in any of the actors?

    And, i currently do have it exactly like swing knight, i just think it would be better for my game if i can keep the character rotating around the thing the rope is attached to, rather than through it. Im looking up 2d physics motion for a pendulum now, thanks for the suggestion :)
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    NtG said:
    I looked at that and there is no code in any of the actors?

    And, i currently do have it exactly like swing knight, i just think it would be better for my game if i can keep the character rotating around the thing the rope is attached to, rather than through it. Im looking up 2d physics motion for a pendulum now, thanks for the suggestion :)

    look at the actors in the scene to see theres rules. THe actors are probably unlocked
  • wormilwormil Member Posts: 127
    If you wanted to swing a full circle, you could use cos and sin for placement and skip the physics of a pendulum.

    I think I have a sample....
  • NtGNtG Member Posts: 103
    JohnPapiomitis said:
    look at the actors in the scene to see theres rules. THe actors are probably unlocked

    ahhhh there we go, thanks.
  • wormilwormil Member Posts: 127
    I use this:
    game.X and game.Y are constrained to the object you are rotating.
    the 70 bigger goes faster, smaller goes slower is the speed, the % is mod so you wrap at 360 for a full circle, * 25 is the offset distance in pixels from the center.

    y = game.Y +sin(( self.Time *70)%360)*25
    x = game.X +cos(( self.Time *70)%360)*25
  • NtGNtG Member Posts: 103
    wormil said:
    If you wanted to swing a full circle, you could use cos and sin for placement and skip the physics of a pendulum.

    I think I have a sample....

    thats what I was trying at first, but it wasn't working for some reason. I would type it all out, but the equations were pretty long.
  • NtGNtG Member Posts: 103
    wormil said:
    I use this:
    game.X and game.Y are constrained to the object you are rotating.
    the 70 bigger goes faster, smaller goes slower is the speed, the % is mod so you wrap at 360 for a full circle, * 25 is the offset distance in pixels from the center.

    y = game.Y +sin(( self.Time *70)%360)*25
    x = game.X +cos(( self.Time *70)%360)*25

    ok, i'll test that out
  • wormilwormil Member Posts: 127
    http://www.trentu.ca/org/trentradio/audiosoup/as_cfrc040131/mm/sine-cosine-animation1.gif

    It turns out using just sin or cos and leaving the other alone is a really good way to make a back and forth motion ;-P
  • NtGNtG Member Posts: 103
    would it be easier to make the rope the pendulum and constrain the character position to the end of the rope?
  • wormilwormil Member Posts: 127
    It's exactly the same as what I gave you then, you still need to calculate the end of the rope given an angle and constant magnitude and your rope still needs to be constrained to the end of hoop or whatever you have it tied on.

    I'll make a demo tonight when I come home from dancing and drinks.
  • wormilwormil Member Posts: 127
    I posted a make shift demo, you'll need to tweak it. It's called Swinging Like A Monkey.

    It needs some work on the starting position, but other than that, I think it is fine.
  • wormilwormil Member Posts: 127
    Also, if you want it to swing for ever, just take the max speed off.
  • NtGNtG Member Posts: 103
    wormil said:
    I posted a make shift demo, you'll need to tweak it. It's called Swinging Like A Monkey.

    It needs some work on the starting position, but other than that, I think it is fine.

    PROPS man, thank you so much for the help!
  • NtGNtG Member Posts: 103
    only problem im having now is that my rope isnt staying attached to the character, either it's growing longer, or my character is getting closer to the anchor. cant figure it out.
  • NtGNtG Member Posts: 103
    nvm fixed it
Sign In or Register to comment.