how place_meeting works

K

kaito

Guest
So my question is how place_meeting would be in the form of a code

I came up with this
Let's imagine that we have two objects player and wall
And both have a square mask

if x-8 <= wall.x-8
{
if x+8 >= wall.x-8 if y-8 <= wall.y-8
{
if y+8 >= wall.y-8 collision = true
}
else if y-8 <= wall.y+8 collision = true
}
else if x-8 <= wall.x+8
{
if x+8 >= wall.x-8 if y-8 <= wall.y-8
{
if y+8 >= wall.y-8 collision = true
}
else if y-8 <= wall.y+8 collision = true
}

I know it's not perfect
So how place_metting in code form looks like for real?
 
T

truckcarr

Guest
I am not entirely sure what your question is asking, but the way place_meeting works is by checking a certain position for a specific object. So one way to use it would to check if a space is empty and if not move there.

//use ! before place_meeting to check if there is NOT a wall at the x,y coordinates.
if(!place_meeting(x+4,y,obj_wall)){
//if there is no wall then the space is empty(well not empty empty but no wall) and we can move there
x+=4;​
}

This is a simple block of code to check if there is a wall four pixels to the right and if not, add 4 to the object's x position.
 
K

kaito

Guest
I want to know source code of place_metting

imagine i created a script that called scr_collision
and i wrote scr_collision() in step event

then i want to see what code is inside of scr_collision

same with place_metting
i just want to know how it locks in a code form
 

Yal

🐧 *penguin noises*
GMC Elder
I know it's not perfect
So how place_metting in code form looks like for real?
Go through list of objects
if type argument2,
then if bounding box overlaps with bounding box of caller instance placed at argument0, argument1,
return true
end if
end other if
end loop
return false
 
K

kaito

Guest
sorry, I do not understand what you're trying to say

what if place_meeting would not exist and other commands that check collision

how you would make collision code?

I want to know what code is inside place_metting
 

Yal

🐧 *penguin noises*
GMC Elder
You can get the bounding box data of sprites (sprite_get_bbox_* family of functions) and you can compare data. They're called bounding box for a reason, they're rectangles. So the math is simple (I think there's even a function that does that for you, called something like rectangle_in_rectangle).
 
K

kaito

Guest
i guess nobody knows?
Or just did not understand what I was asking about?
 

samspade

Member
i guess nobody knows?
Or just did not understand what I was asking about?
Yal pretty much answered your question. There's really no reason someone would take the time to turn that answer into actual game maker code though. Game Maker (really most languages) provide functions precisely so no one has to spend the time to do so. If there is a non-academic reason you want to know how the code works (i.e. there is something you're trying to do that place_meeting doesn't accomplish) you should ask that question and someone would probably answer it.
 
K

kaito

Guest
of course I can just write if place_meeting(x,y,wall) then do something and don't care about it
but I am just interested how its works
i want to see how it locks in a form of game maker language
 

Gamebot

Member
This is just a portion from the STEP event in a player object. Checking for a platform underneath.

Code:
 if(bbox_right < Platform.bbox_left || bbox_left > Platform.bbox_right || vsp_final < 0){
 
     Platform = noone;
    
    }
}

if(Platform){
   y += myPlatform.bbox_top - bbox_bottom;  //Snap the player to the top of the platform
}
 
Top