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

SOLVED Need help with Grappling hook, please :(

xNYARLx

Member
Hello.
I try making Grappling hook.

First problems:
The point is that it is to be controlled from the keyboard: left, right, up, down arrows and "D" button to use hook. !NOT USE MOUSE!
I made obj_solid_s to grab it and it does it but only one on the board (I have 5 obj_solid_s on board) and in the same place (in the middle of obj_solid_s) and from anywhere on the board.
I no a PRO, somebady can help me?

Second problem:
!Interest me too how change this:
//Position of rope where we clicked
grappleX = mouse_x;
grappleY = mouse_y;
when i dont use mouse.!

Thanks for helping anyway...


I make something like this:

obj_player
CREATE
GML:
active = false;
mx = x;
my = y;
grav = grav_default;
grav_default = 0.2;
STEP
GML:
// HOOK
if keyboard_check_pressed(ord("D"))
{
    if(instance_exists(obj_solid_s))
    {
        active = true;
    }
}

if (active = true)
{
    grav = 0.1;
    x += (mx - x) * 0.1;
    y += (my - y) * 0.1;
}

if keyboard_check_released(ord("D"))
{
    active = false;
}

if(active = false)
{
    grav = grav_default;
}
DRAW
GML:
draw_self()
if (active = true){
    draw_line(x,y,mx,my);
}
 
Last edited:

rytan451

Member
Create a "obj_target" object. Set grappleX and grappleY to the position of the obj_target when the relevant key is pressed, and move obj_target using arrow keys.

Can you explain what you mean by this?

I made obj_solid_s to grab it and it does it but only one on the board (I have 5 obj_solid_s on board) and in the same place (in the middle of obj_solid_s) and from anywhere on the board.
Here's what I understand from it: You made an obj_solid_s to grab the grappling hook, which it does. However, there is only one obj_solid_s instance, and there are 5 obj_solid_s instances in the same place. That place is in the middle of the one instance of obj_solid_s, and it comes... from anywhere on the board.

Since my understanding is obviously flawed (including contradictions), would you kindly enlighten me with what you mean?
 

Nidoking

Member
I don't think you understand how variables work. You're setting grav equal to grav_default before you've set grav_default. I don't understand how that even works. It should throw an error at runtime.

You're also setting mx and my to the initial position of your obj_player, and then I don't see you ever changing them. You're always going to draw that line from your current position to the original position.

Your obj_solid_s problems are probably due to not understanding the difference between objects and instances.

Finally, if you want to replace mouse_x and mouse_y with something else, you use the Delete or Backspace key on your keyboard to remove those variables and use the other keys to type the thing you want instead. You need to figure out what position you want to use instead of the mouse position. Is it, perhaps, the x of the obj_player and the y of whatever obj_solid_s is directly above the player? Then that's what you use. This is what we call design, and you need to learn to do it.
 

Geners

Member
It seems like you're just adding 0 to the objects x and y values every step while the user is pressing the D key

You set mx and my to x and y

Then in the step event you subtract x by x and then multiply them by 0.1... which would always be 0.
 
Top