Legacy GM object collision problem

D

Dzoksi

Guest
Hi everyone, I'm new with Gamemaker. So I have problem, probably because of myself :)
Sorry if my english is not good :)

Well, I'm creating game where you pick up an object and with mouse move it and drop it where you want, and if some other object is already at this position, first object needs to go back to previous position. It is grid moving.
Objects are like that in tetris game.
So, my problem is..
I used place_meeting, position_meeting, instance_position..etc, but when I drop first object NEXT to other, there is collision. How to fix this?
Origin set to center, collision mask is precise, I even make collision mask smaller than sprite.

Probably I'm missing something, but I dont know what :)
 

jo-thijs

Member
Hi everyone, I'm new with Gamemaker. So I have problem, probably because of myself :)
Sorry if my english is not good :)

Well, I'm creating game where you pick up an object and with mouse move it and drop it where you want, and if some other object is already at this position, first object needs to go back to previous position. It is grid moving.
Objects are like that in tetris game.
So, my problem is..
I used place_meeting, position_meeting, instance_position..etc, but when I drop first object NEXT to other, there is collision. How to fix this?
Origin set to center, collision mask is precise, I even make collision mask smaller than sprite.

Probably I'm missing something, but I dont know what :)
Hi and welcome to the GMC!

I'm not 100% sure what your exac issue is.
As I'm understanding it, you've got objects arranged in a grid.
You want to teleport some object to a new location on the grid.
You first perform some collision checks,
but those give false positives when you try to move an object
to a free spot, right next to an occupied spot on te grid.
Is that correct?

In that case, I would like to ask what code you're currently using
and what the hitboxe widths and heights and such are,
as well as the widths and heights of the cells in the grid.
 
D

Dzoksi

Guest
Hi :)

I have 8 objects in the grid. It like draggable puzzle game.

"You first perform some collision checks,
but those give false positives when you try to move an object
to a free spot, right next to an occupied spot on te grid." Yes, it's correct :)

in obj Create event:
image_speed = 0;
grabbed = false;
xx = 0;
yy = 0;

in obj Snap event:
if (grabbed)
{
x = mouse_x + xx;
y = mouse_y + yy;
move_snap(mouse_x & ~31,mouse_y & ~31);
}

in obj Left pressed
grabbed = true;
depth = -1;
xx = x - mouse_x;
yy = y - mouse_y;

in obj left released
grabbed = false;
depth = 0;
if place_meeting(mouse_x, mouse_y, obj_random) - // obj_random is parent of 8 objects
{
show_message("ok")
}
-------------------------------------------------------------
cell size: 32x32
Objects are like rectangle, square..

Thank you for your help :)
 

jo-thijs

Member
Hi :)

I have 8 objects in the grid. It like draggable puzzle game.

"You first perform some collision checks,
but those give false positives when you try to move an object
to a free spot, right next to an occupied spot on te grid." Yes, it's correct :)

in obj Create event:
image_speed = 0;
grabbed = false;
xx = 0;
yy = 0;

in obj Snap event:
if (grabbed)
{
x = mouse_x + xx;
y = mouse_y + yy;
move_snap(mouse_x & ~31,mouse_y & ~31);
}

in obj Left pressed
grabbed = true;
depth = -1;
xx = x - mouse_x;
yy = y - mouse_y;

in obj left released
grabbed = false;
depth = 0;
if place_meeting(mouse_x, mouse_y, obj_random) - // obj_random is parent of 8 objects
{
show_message("ok")
}
-------------------------------------------------------------
cell size: 32x32
Objects are like rectangle, square..

Thank you for your help :)
I see 2 mistakes.
1) This line:
Code:
move_snap(mouse_x & ~31,mouse_y & ~31);
should actually be this:
Code:
move_snap(32, 32);
but that won't cause any trouble unless your mouse is located in the first row or column of the grid.

2) This line:
Code:
if place_meeting(mouse_x, mouse_y, obj_random) - // obj_random is parent of 8 objects
should actually be this:
Code:
if place_meeting(x, y, obj_random) - // obj_random is parent of 8 objects
as the mouse coordinates are not yet snapped to te grid.
 
D

Dzoksi

Guest
I changed everything, but problem is still there :/ it also happens, that I just click on object (while it is next to another object) and shows that there is collision.
is it possible that it depends on where i released object? (i mean in the one cell, px left, px right). Because, when I click on object, once it shows collision, once not.
 

jo-thijs

Member
I changed everything, but problem is still there :/ it also happens, that I just click on object (while it is next to another object) and shows that there is collision.
is it possible that it depends on where i released object? (i mean in the one cell, px left, px right). Because, when I click on object, once it shows collision, once not.
That certainly is possible and even probable.
If this didn't solve the issue though, I'd need some more info about your project.
The fastest option would be for you to temporarily upload the GMZ file of your project (file > export project) somewhere online (mediafire, dropbox, onedrive, google drive, ...) and share the link.
 
D

Dzoksi

Guest
The issue is caused by objects such as obj_rozi having set their mask to something like spr_mask_rozi, instead of <same as sprite>.
The masks you've given them don't match the shape/size of the sprites they have and the mask is used in collision detection.
You are the King :) Thank youu :)

I have one more question, I hope I'm not boring :) in which direction I need to go, if I want to make it that if the object (before I want to release) is half on the imaginary space (where user/player need to solve puzzle) and half is outside that space? And when I release, the object need to go with whole area or on that space, or outside. If you understand what I want to say :)
 

jo-thijs

Member
You are the King :) Thank youu :)

I have one more question, I hope I'm not boring :) in which direction I need to go, if I want to make it that if the object (before I want to release) is half on the imaginary space (where user/player need to solve puzzle) and half is outside that space? And when I release, the object need to go with whole area or on that space, or outside. If you understand what I want to say :)
It'd probably be best to always put it outside the main field (imaginary space) when overlapping both.
The biggest question would be how you want to represent the main field in your project.
Personally, I would use width, height, x_offset and y_offset variables in a controller object and perform some checks based on that.

Alternatively, you can use a rectangle-shaped object that covers and represents the main area.
You can the use collision checking to check if the object overlaps with the main area.
You can perform some checks with the bbox_* variables to check if the object overlaps the complement/outside of the main area
or you can place invisible rectangle-shaped border objects with which you can perform collision checks.

I suppose, since you said you're new to GameMaker,
the second option might seem more intuitive at first and it will probably suffice for what you're trying to do,
but having a controller object will generally be a better idea.
 
D

Dzoksi

Guest
It'd probably be best to always put it outside the main field (imaginary space) when overlapping both.
The biggest question would be how you want to represent the main field in your project.
Personally, I would use width, height, x_offset and y_offset variables in a controller object and perform some checks based on that.

Alternatively, you can use a rectangle-shaped object that covers and represents the main area.
You can the use collision checking to check if the object overlaps with the main area.
You can perform some checks with the bbox_* variables to check if the object overlaps the complement/outside of the main area
or you can place invisible rectangle-shaped border objects with which you can perform collision checks.

I suppose, since you said you're new to GameMaker,
the second option might seem more intuitive at first and it will probably suffice for what you're trying to do,
but having a controller object will generally be a better idea.
Once more, thank you for your advices. I'll try and go with controller object and see how far I will get :)
 
Top