Creation of a Box2D hook like the one seen on iOS Mikey Hooks game

Did you play Mikey Hooks? It’s an excellent platform where the hero can fire hooks and jump over spikes, holes and monster… and obviously the game is much more than this but I wanted to create some kind of hook with Box2D.

I made a very basic hook some time ago in the post Simulating a hook with Box2D but this is way better, here is how it works:

Each time you click on a static body (let’s say a rock), you create a distance joint between a dynamic body (let’s say the hero) and the static body.

Keeping the mouse down will rewind the hook, that is the distance joint is shortened, giving you a “Bionic Commando” effect.

Releasing mouse button will destroy the joint and you will be able to fire another hook.

This way you can swing around the stage.

Here is the code:

And this is the result:

Click and hold your mouse over a static body to create a hook and rewind it, release mouse button to destroy the hook. Try to swing like a tarzan geek.

Download the source code.

  • Carlos Ribeiro

    Awesome!

  • This is a great tutorial. Thanks Emanuele. I’ll try to make this game in as2 (:

  • MC

    i always wanted to know how to do THAT… Thanks!!

  • MC

    bytheway,…. How can you skin the world floors/platforms like that?
    i suppose is using masks (?) or is it bitmap filling?, or how can you do it properly in AS3 & Box2D?

  • That is so super awesome! I’m going to make my own 80s spiderman game :D I played one when I was young, and one of the funniest things about it was simply swinging back and forth from everything.

  • Peri

    this reminds me of green character from one of the best platform games I’ve ever played, Fury of the Furries!! Thanks!!

  • SadiQ

    I ported this one to Stencyl. Was too lazy to actually draw the hook line or mess with the mass of the actor so it feels a little different than your tut. Here’s what I have and thanks for these tuts: http://www.stencyl.com/game/play/21417

  • SadiQ

    A question that’s been on my mind since I saw this post…
    How would one make the joint collide with the boxes that you create? (Since there is no way to test for collisions between a joint and a body)
    That would recreate the worms like rope behavior from the old game.

  • Pingback: Creation of an hook using Nape Physics Engine and Distance Joint - Emanuele Feronato()

  • Hi emanuele,
    We should set isHooked to false after releasing hook, else it might give problem when trying to destroy same hook jint again during fire.

    Your tutorial helped me a lot for my cocos2d-x project.
    Thanks,

  • Hi emanuele,
    We should set distanceJoint to false after releasing hook, else it might give problem when trying to destroy same hook joint again during fire.

    Your tutorial helped me a lot for my cocos2d-x project.
    Thanks,

  • Hi emanuele,
    We should set distanceJoint to false after releasing hook, else it might give problem when trying to destroy same hook joint again during fire.

    Your tutorial helped me a lot for my cocos2d-x project.

    void HelloWorld::releaseHook(){
    if (distanceJoint) {
    world->DestroyJoint(distanceJoint);
    distanceJoint = false;
    }
    }

    void HelloWorld::manageHook(){
    if (isHooked) {
    hero->SetAwake(true);
    if (distanceJoint) {
    distanceJoint->SetLength(distanceJoint->GetLength()*0.99);
    }
    }
    }

    Thanks,

  • How would you set things up so that when releasing the hook, the hero still has some upwards momentum? the only way I can see how to do that currently would be to get the vector of the hero when the hook is released, and then keep applying it to the hero.

  • A great tutorial, I will definitely be using this in the near future.

  • Pingback: Creación de un gancho en Box2D como el que se ve en el juego de iOS Mikey Hooks | Todotuto.cl()

  • Pingback: Two games you will play this Christmas - Emanuele Feronato()

  • wow., it’s awesome.. :)