Totemi1324
Member
Hello,
So I have sort of a special situation, since I can't find any existing solutions online. I am programming a Drag and Drop puzzle game and I need to drag an object around in a grid. Here's a snapshot so you can picture my goal:
So I need to drag the circle along this grid and get it to the exit seen on the right. My problem is I tried many approaches for doing this and none of them works properly. For example, I tried to put walls in between the paths (marked red in the following picture), mark it and the ball (hitbox = same size as wall blocks) as solid and to work with the
The problem with this is that the movement is very chunky and if you don't line the mouse correctly on that single pixel, the box does not move. I don't want to make the hitbox smaller because I want the circle to stay on one clearly defined, straight path while moving. I tried to implement a system for snapping the ball to a position if it's nearby and not exactly but just near the path, but that also does not work very well:
I am sure this can be done better and more functional, so can you suggest a way how to solve this movement problem, please?
Thanks!
So I have sort of a special situation, since I can't find any existing solutions online. I am programming a Drag and Drop puzzle game and I need to drag an object around in a grid. Here's a snapshot so you can picture my goal:
So I need to drag the circle along this grid and get it to the exit seen on the right. My problem is I tried many approaches for doing this and none of them works properly. For example, I tried to put walls in between the paths (marked red in the following picture), mark it and the ball (hitbox = same size as wall blocks) as solid and to work with the
place_free()
command:The problem with this is that the movement is very chunky and if you don't line the mouse correctly on that single pixel, the box does not move. I don't want to make the hitbox smaller because I want the circle to stay on one clearly defined, straight path while moving. I tried to implement a system for snapping the ball to a position if it's nearby and not exactly but just near the path, but that also does not work very well:
Code:
//Create:
moving = false;
y_lanes = [240, 400, 560, 720, 880]; // Positions of all horizontal lanes
x_lanes = [1520, 1360, 1200, 1040, 880, 720, 560, 400]; Positions of all vertical lanes
//Step:
if (position_meeting(mouse_x, mouse_y, self) && mouse_check_button_pressed(mb_left)) {
moving = true;
}
if (moving) {
target_x = mouse_x;
target_y = mouse_y;
if (place_free(target_x, y) && point_distance(x, y, target_x, y) < 100) x = target_x;
else {
for (i = 0; i < array_length(x_lanes); i++) {
if (target_x < x_lanes[i] + 30) && (target_x > x_lanes[i] - 30) && (point_distance(x, y, target_x, target_y) < 100) {
x = x_lanes[i];
break;
}
}
}
if (place_free(x, target_y) && point_distance(x, y, x, target_y) < 100) y = target_y;
else {
for (i = 0; i < array_length(y_lanes); i++) {
if (target_y < y_lanes[i] + 30) && (target_y > y_lanes[i] - 30) && (point_distance(x, y, target_x, target_y) < 100) {
y = y_lanes[i];
break;
}
}
}
if (mouse_check_button_released(mb_left)) moving = false;
}
Thanks!