Animating a hammer to move back and forth..?

LokitoesLokitoes Member, PRO Posts: 187

Hi all,

I'd like to make a simple actor of a hammer that swings back and forth, as if someone was using it to hammer something. I'm hoping to do this without making a frame-by-frame animation. Is there a way to, say, control the angular velocity so that it swings back and forth rather than completing a full circle? Or some other attribute? I'd like it to rotate forwards by about 90 degrees, then back to its starting point, and for this to loop.

I'm going to eventually have it on a move rule so that the player can move it around, so I'd like it to continue this angular movement both when it isn't being used, and when other rules are being applied to it.

Cheers!

Comments

  • JimmyMesserJimmyMesser LondonMember Posts: 235

    maybe interpolate. Not sure if you will need timers but I'm sure you can do it.

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @Lokitoes said:
    I'd like it to rotate forwards by about 90 degrees, then back to its starting point, and for this to loop.

    Empathy points off for the use of the mathematically arbitary phrase 'rotate forwards' :tongue: !?

    You just need to constrain the hammer to an orbit that itself is constrained to just the upper values of an incrementing angle's sin function.

    Here a 'hammer' is assumed to be a single image that is oriented so that the head of the hammer is at the 0° position (3 o'clock / 'pointing' right) - so an actor that is wider than it is taller as the hammer is effectively lying on its side.

    The rules should look something like this:

    Constrain X position to:
    half the hammer's width multiplied by the cos of (range of movement abs(sin(anglespeed multiplier )))+offset value X

    Constrain Y position to:
    half the hammer's width multiplied by the sin of (range of movement abs(sin(anglespeed multiplier )))+offset value Y

    Constrain Rotation to:
    range of movement abs(sin(anglespeed multiplier ))

    . . . . .

    If you want the hammer to continuoulsy loop then take the lazy option and just make the 'angle' = self.time (or game.time) so the angle just keeps increasing and your hammer keeps swinging.

    . . . . .

    @Lokitoes said:
    I'm going to eventually have it on a move rule so that the player can move it around, so I'd like it to continue this angular movement both when it isn't being used, and when other rules are being applied to it.

    Simply use the offset values to control the offset movement of the hammer.

    Hold on, let me make a quick demo, back in a minute . . . .

  • SocksSocks London, UK.Member Posts: 12,822

    Here's the basic movement (file attached)

    Actual constrain values used (for a 200 x 100 pixel actor)

    X = 100 *cos(90 *abs(sin( self.Time *300)))+ X offset
    Y = 100 *sin(90 *abs(sin( self.Time *300)))+ Y offset
    R = (90 *abs(sin( self.Time *300)))

    . . . . . .

    The 100 is half the width of the hammer (effectively half the height as the hammer is on its side).

    The 90 is a 90° range of movement - turn this down (for example to something like 20) and you will get a gentle hammering action, turn it up above 90 and it will move more towards a manic hammering action.

    The *300 controls the speed of the hammering.

    The offset values are the absolute offsets, use these values to move the whole system around the screen - for example if you use mouse position X for the X offset and mouse position Y for the Y offset the swinging hammer will follow the mouse.

  • SocksSocks London, UK.Member Posts: 12,822

    Here is the same idea, but I've thrown in a 'grab box' with which you can move the hammer around, obviously you'd make this grab box invisible, I left it visible just so you could see it. File attached. You could of course move the hammer by clicking on the hammer itself (rather than a controller like this grab box), but with the hammer swinging it can be tricky to grab.

  • LokitoesLokitoes Member, PRO Posts: 187

    Cool thanks guys I'll give this and the pendulum movement a go. :) haha sorry about the wording - never learnt maths or science at high school - I'm from rural Australia, which probably speaks for itself.

  • LokitoesLokitoes Member, PRO Posts: 187

    Thanks for that example @Socks I'll definitely be pillaging from that :D

  • LokitoesLokitoes Member, PRO Posts: 187

    Not sure if you can view this, but this 3D projection mapped artwork was the outcome of this thread's mission :) I don't have the proper footage yet, this is just a bit of footage taken by a stranger on instagram, but basically the artwork 'falls down' and the hammers come along and fix it back into place. Not interactive though, as it's an impossible struggle to get .app files and my mapping software to talk to each other.

Sign In or Register to comment.