• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Pendulum swing grapple hook

Hi everyone, I am trying to figuring out how to make a grapple hook for my character. Here is an example of what id like to do.

if character is airborn

if button pressed

Grapple hook shoots out 45 degrees upward the way I am facing, if place_meeting with grappleBlock, rope appears from my character to that block. Character then swings in a pendulum motion at the current run speed.

If button released, rope disappears and character drops at current momentum.


I am a bit of a noob still so if you could explain it to me as best you can I'd really appreciate it. Or i'd be happy to play about with code examples.

Thanks every one
 
V

VagrantWhaleGames

Guest

quick search and youtube came up with this...



heres something off the top sort of from the vid...

Code:
if(mouse_check_button(mb_left))
{
spd = 1;
xx = mouse_x;
yy = mouse_y;
draw_line(x,y,xx,yy)
move_towards_point(xx,yy,spd);
}
 
Hey, thanks for the reply. I've actually done this tutorial and am currently trying to expand on it. But was keep getting stuck. Perhaps I am trying to run before I can walk.
I am able to find all the elements of what through different tutorials, I am just having trouble in implementing them into one.
 
Hey all, Ok so I have finished Shauns rope swing tutorial and its incredible. Now I've I been trying a few things to get it to work as a projectile. I think I near have it but somethings slightly off. So here goes...

My character has a grapple gun that fires out the hook. it uses this code.

Code:
hookShoot = gamepad_button_check_pressed (0, gp_shoulderr);


if (hookOut == false) && (hookShoot)
{
    with instance_create_layer(x,y,"GrappleHook",oHook)
    {
        speed = 30;
        direction = other.image_angle;
        image_angle = direction;
    }
    hookOut = true;
}

else if hookShoot
{
    hookOut = false;
}
Then My hook has a collision event that returns if it is or isn't hooked to a grapple point.

Code:
hooked = true;
Now, on my character I say this...

Code:
with (oHook)
        {
            if (hooked == true)
           
            {
                grappleX = oHook.x;
                grappleY = oHook.y;
                ropeX = x;
                ropeY = y;
                ropeAngleVelocity = 0;
                ropeAngle = point_direction(grappleX,grappleY,x,y);
                ropeLength = point_distance(grappleX,grappleY,x,y);
                state = pState.swing;
            }
        }
The hook fires but no swing state. Is this because It thinks I want the hook to enter swing state? It works if I remove the "with(oHook)" and manually place a oHook in the room.
Any ideas?
 
Ok I worked it out. I fed the bool from the hook back to the character.
Code:
        if (hooked == true)
        {
            grappleX = oHook.x;
            grappleY = oHook.y;
            ropeX = x;
            ropeY = y;
            ropeAngleVelocity = 0;
            ropeAngle = point_direction(grappleX,grappleY,x,y);
            ropeLength = point_distance(grappleX,grappleY,x,y);
            state = pState.swing;
        }
As simple as that.
 
Top