• 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 Slingshot Movement Help?

D

Drew G

Guest
I'm working of a combat mechanism for my game that involves a sumo style mechanic where you push opponents out of the ring. To incorporate this with the drag and drop elements I've used in the UI, I'm looking to create a mechanic similar to that in Neutronized's mobile game Slime Pizza. I was wondering if anyone has done this previously or has any idea of how they would do it and would be willing to share. I am working in the lite version of GM8.1 currently, but am looking to upgrade to Studio 2 shortly, but I would prefer functions from the former if possible. Thank you so much in advance!
 
D

Drew G

Guest
Oh sorry. I've used two objects, which I call "sling" and "stone." The sling is invisible can be dragged. It records the distance between it and the stone in a step event. When the sling is released it adds the distances to the current x and y positions of the stone and the stone jumps to that point. The problem lies in making a smooth movement and adding a sense of gravity without physics.

Here is the my extremely messy code (this is a prototype so I have all uninitialized variables set to 0, this will be fixed later):

SLING:

Create:
Code:
drag_start = 1;
global.sling_able = 0;
Step:
Code:
//Allows you to drag the object
if (mouse_check_button_pressed(mb_left)) {
    if position_meeting(mouse_x,mouse_y,id) {
        drag_true = 1;
    }
    else {
       drag_true = 0;
    }
}


if mouse_check_button(mb_left) && drag_true = 1{
    x = mouse_x;
    y = mouse_y;
    drag_start = 1;
    alarm_set = 0;
    drag_stopped = 0;
    global.sling_able = 0;
}
else {
    drag_start = 0;
}

if drag_stopped = 1 {
    if point_distance(x, y, stone.x, stone.y) > 5 {
        move_towards_point(stone.x, stone.y, (point_distance(x, y, stone.x, stone.y)) * 0.25);
    }
    else {
        move_towards_point(stone.x, stone.y, 0.5);
    }
}
else {
    speed = 0;
}

if alarm_set = 0 && drag_start = 0 {
    alarm[0] = 1;
    alarm_set = 1;
}
//Measures the distance
global.internal_distance_x = stone.x - x;
global.internal_distance_y = stone.y - y;
Alarm 0:
Code:
drag_stopped = 1;
global.sling_able = 1;
Mouse Left Released:
Code:
global.distance_x = stone.x + global.internal_distance_x;
global.distance_y = stone.y + global.internal_distance_y;

STONE:

Create:
Code:
//The positions to start in
global.distance_x = 160;
global.distance_y= 160;
Step:
Code:
if global.sling_able {
x = global.distance_x;
y = global.distance_y;
}
 
Last edited by a moderator:
Top