• 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!

Grappling Hook/HookShot mechanic

C

Chill

Guest
So the next mechanic im trying to wrap my head around is a hookshot/grapple mechanic, trying to find a decent video on youtube has been difficult, figured i would try to see if someone has set something up like this before,
right now my code is this for key im using for it, ive created a 1X1 pixel for creating the rope, and thats pretty much what ive got so far.

What i'd like it to do is attach only to certain objects or grapple points that are a certain distance away i'm thinking about 75 pixels, otherwise it will just draw the grapple line and fall or curl up, i also want to use the grapple to grab items, and will be using it in a boss fight to pull a mask off. The project is not for any commercial use, and is for a Game Development class, any help with the mechanic would be appreciated greatly as my team members are not much help.

if (gkey) {
switch (itemSelected){
case 1: //torch
if (place_meeting(x,y, obj_large_torch)){
obj_large_torch.activate = true;
}
else {
if (!instance_exists(obj_light_player)){
instance_create(obj_player.x,obj_player.y, obj_light_player);
}
else
{
with(obj_light_player) {
instance_destroy();
}
}
}
break;
case 2: //grapple


break;

case 3: //crossbow
if (ammo > 0) {
if (!shot) {
instance_create(x,y,obj_arrow);
shot = true;
ammo -= 1;
alarm[1] = 10;
}
}

break;
}

}
 
C

Chill

Guest
so been tinkering around a bit and i've almost got a rope to form

ive added to my obj_grapple
CREATE:
// initialize the grapple line

grapplex = mouse_x;
grappley = mouse_y;
reached = false;
distance = 100;
grapplespeed = 2;
grapplefinished = false;

STEP:
/// create a line to the grapple point
if (distance > 0) {
var gpoint = instance_create(x,y,obj_grapple);
gpoint.distance = 0;
move_towards_point(grapplex, grappley, 2);
distance -= 1;
}
if (distance == 0 && place_meeting(x,y,obj_grapplespot)) {
obj_player.grappled = true;



}
if (grapplefinished) {
instance_destroy();
}

My Player Step Event Statement that handles the grapple:

if (gkey) {
switch (itemSelected){
case 1: //torch
if (place_meeting(x,y, obj_large_torch)){
obj_large_torch.activate = true;
}
else {
if (!instance_exists(obj_light_player)){
instance_create(obj_player.x,obj_player.y, obj_light_player);
}
else
{
with(obj_light_player) {
instance_destroy();
}
}
}
break;
case 2: //grapple
if (!grappled) {
var hook = instance_create(x,y,obj_grapple);
}
if (grappled) {
obj_grapple.grappledfinished = true;
grappled = false;
}


break;

case 3: //crossbow
if (ammo > 0) {
if (!shot) {
instance_create(x,y,obj_arrow);
shot = true;
ammo -= 1;
alarm[1] = 10;
}
}

break;
}

}
 
G

Gerald Tyler

Guest
I too am interested in this. For mine enemies the same size as the character will be pulled towards the character. But there will also be stationary targets that the player can use to bridge the gaps by moving the character towards them. Grappling hooks sure are a tricky thing O___O
 
C

Chill

Guest
So tinkering around some more ive managed to get my character to grapple once at least, something's not being reset after the grapple, this is what i have so far in the step event, i'm also wondering if there is a cancel command to move to point, googled a bit and came up with somewhat a solution of setting the speed to 0 after reaching the point but im not sure if i should be doing that....

if (gkey) {
switch (itemSelected){
case 1: //torch
if (place_meeting(x,y, obj_large_torch)){
obj_large_torch.activate = true;
}
else {
if (!instance_exists(obj_light_player)){
instance_create(obj_player.x,obj_player.y, obj_light_player);
}
else
{
with(obj_light_player) {
instance_destroy();
}
}
}
break;
case 2: //grapple
if (!grappled) {
var hook = instance_create(x+(18*face),y-5,obj_grapple);
grapplex = mouse_x;
grappley = mouse_y;
grapplespeed = 5;
grav = 0;
}
if (grappled) {
obj_grapple.grappledfinished = true;
grappled = false;
}


break;

case 3: //crossbow
if (ammo > 0) {
if (!shot) {
instance_create(x,y,obj_arrow);
shot = true;
ammo -= 1;
alarm[1] = 10;
}
}

break;
}

}

if (grappled) {
move_towards_point(grapplex, grappley, grapplespeed);
if (distance_to_object(obj_grapplespot) <= 3) {
grappled = false;
grapplespeed = 0;

}
}
if (!grappled) {
grav = 0.5;
}
 
K

KaptKaboose

Guest
I don't have anything quite down yet, though I'm making a grapple mechanic myself. I just wanted to let you know though that you might want to throw in some states to handle your character. As it looks now, I think you're on a slippery slope to reaching a point where your code gets too hectic and confusing. I mean this in no negative way lol. This is coming from someone who has done that way too many times. So I would make scripts for like move_state, grapple_state, attack_state, etc. And each of those scripts will carry out whatever needs to happen while in that state. When conditions are met, you can set (in your player) state = whatever_state; Then in your step event, script_execute(state);
 
C

Chill

Guest
thanks KaptKaboose, i also think the code is a bit hectic and confusing, first project im doing with game maker for a class, future endeavors i probably will organize a bit more with state scripts, thanks for the advice
 
Top