how place_meeting works

Discussion in 'Programming' started by kaito, Aug 29, 2017.

  1. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    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?
     
  2. truckcarr

    truckcarr Member

    Joined:
    Aug 29, 2017
    Posts:
    1
    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.
     
  3. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    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
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,688
    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
     
  5. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    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
     
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,688
    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).
     
  7. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    I know but I am not asking about that
     
  8. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    i guess nobody knows?
    Or just did not understand what I was asking about?
     
  9. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,017
    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.
     
  10. kaito

    kaito Member

    Joined:
    Aug 29, 2017
    Posts:
    28
    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
     
  11. Gamebot

    Gamebot Member

    Joined:
    Jul 3, 2016
    Posts:
    182
    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
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice