• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Collision Check Between Two Objects

Status
Not open for further replies.

chidsuey

Member
Is there some way to do this from a third object? If there is, I can't find it.

Example:
if(collision_check(obj1,obj2) {Do stuff};


And how does the drag and drop collision event work? I also can't find script for..

if (collision_with_own_mask) {do stuff}

Thanks as always for your help!
 

jo-thijs

Member
Code:
with obj1
    if place_meeting(x, y, obj2)
        with other {
            Do stuff
        }
I'm not entirely sure what you mean with collision_with_own_mask though.
Collision with own mask and what?
Are you asking for place_meeting?
 
  • Like
Reactions: 607
M

Multimagyar

Guest
one asks for the x and y because it would like to know which precise point you want to check for collision (position_meeting). The other asks what is the position where you want to move the mask to check for the position (place_meeting). the "this object" collide with "that object" is practically your collision event. That's the event that will asks the question if two object are in some sort of contact.
 

chidsuey

Member
I'm afraid I still don't understand. None of this boils down to "If I touch you" and I can't figure out how you're supposed to do that with code. I see "If that touches this precise point" (position_meeting), but I don't understand how that's different from place meeting.
 

FrostyCat

Member
I'm afraid I still don't understand. None of this boils down to "If I touch you" and I can't figure out how you're supposed to do that with code. I see "If that touches this precise point" (position_meeting), but I don't understand how that's different from place meeting.
place_meeting() checks the entire collision mask of the current instance, while position_meeting() checks one single point.

Read this: What's the difference: collision functions
 

chidsuey

Member
So if I want to check collision with a moving enemy, it would be:

place_meeting(obj_enemy.x,obj_enemy.y,obj_enemy);

?
 

jo-thijs

Member
place_meeting(X, Y, OBJ) sets the x and y coordinates of the executing instance to X and Y respectively.
It then checks to see if there's a collision between the executing instance and any other instance of type OBJ.
It then resets the x and y coordinates to what they were before calling place_meeting and returns the result.
The reason this function asks for X and Y coordinates is because you don't always want to know
if the executing instance currently collides, but if it would collide if it were placed a couple of bits further.
For example, you can check if the instance is on the ground by checking if the instance would collide with the ground if it were placed 1 pixel lower.
You would then use place_meeting(x, y + 1, obj_ground).
 

NightFrost

Member
Generally speaking, place_meeting() allows for inserting x and y coordinates to answer the question "if I was moved there, would I collide with OBJ?" This is often used for motion collision detection purposes; you check whether there would be a collision before you move and then adjust accordinly, instead of first moving - then checking for collisions - then doing complicated backtracking because there was a collision with a wall you must not walk into. If you just want to check for collision in your exact current position, you simply insert current x and y.
 

Yal

GMC Memer
GMC Elder
Then what is the purpose of the x and y arguments?
The purpose is to check whether there would be a collision where you're trying to move, which is often more useful than whether there currently is a collision - if you check for walls, for instance, checking whether you can move somewhere just needs one check if there is a collision. If you could only check your current position, you'd need to move, check for collisions, and if there are any, move back... which is a lot less convenient.
 

FrostyCat

Member
So if I want to check collision with a moving enemy, it would be:

place_meeting(obj_enemy.x,obj_enemy.y,obj_enemy);

?
This response makes it quite obvious you have not properly read the article I showed you.
The article said:
Functions those named place always put the current instance that is executing the code at the specified position and checks if its sprite (or mask if assigned) collides with another object.
A sensible person in your situation would not think about putting the current instance over some other enemy's coordinate and then checking for a collision. The right thing to do is putting the current instance at its current position and then checking for a collision.
Code:
place_meeting(x, y, obj_enemy)
 

chidsuey

Member
place_meeting(X, Y, OBJ) sets the x and y coordinates of the executing instance to X and Y respectively.
It then checks to see if there's a collision between the executing instance and any other instance of type OBJ.
It then resets the x and y coordinates to what they were before calling place_meeting and returns the result.
The reason this function asks for X and Y coordinates is because you don't always want to know
if the executing instance currently collides, but if it would collide if it were placed a couple of bits further.
For example, you can check if the instance is on the ground by checking if the instance would collide with the ground if it were placed 1 pixel lower.
You would then use place_meeting(x, y + 1, obj_ground).
Thank you! This helped a lot. So if you wanted to test the object in it's current position, you would simply do:

place_meeting(x,y,object)

I was confused because it seemed like the x and y were for the other object. Thanks again!
 
K

Krano Network Squirrell

Guest
I've been trying to use place_meeting for object collision with the floor and it doesn't let me move at all until my character is no longer on the floor (AKA when jumping)
 

TheouAegis

Member
Typically for floors people use place_meeting(x, y+1, floor).

Also make sure your floor isn't solid. I mean, it can be, but sometimes not moving is because the object is solid.
 
Status
Not open for further replies.
Top