Collision Check Between Two Objects

Discussion in 'Programming' started by chidsuey, Aug 26, 2016.

Thread Status:
Not open for further replies.
  1. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    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!
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    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?
     
    607 likes this.
  3. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    Doesn't place meeting check a point in the room to see if there's an instance of an object there?
     
  4. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    No, that's position_meeting, place_meeting takes the mask of the executing instance into account.
     
  5. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    Then what is the purpose of the x and y arguments? Why isn't just 'this obj' and 'that obj'?
     
  6. Multimagyar

    Multimagyar Member

    Joined:
    Jun 20, 2016
    Posts:
    144
    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.
     
  7. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    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.
     
  8. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,461
    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
     
  9. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    So if I want to check collision with a moving enemy, it would be:

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

    ?
     
  10. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,788
    If you put it in the end step event. And remove the obj_enemy.'s in that code. They are pointless.
     
  11. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    Sorry I feel like I'm getting a lot of different answers. I still don't understand.
     
  12. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    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).
     
    chidsuey likes this.
  13. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,923
    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.
     
  14. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,570
    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.
     
  15. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,461
    This response makes it quite obvious you have not properly read the article I showed you.
    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)
    
     
  16. chidsuey

    chidsuey Member

    Joined:
    Aug 22, 2016
    Posts:
    45
    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!
     
  17. Krano Network Squirrell

    Krano Network Squirrell Member

    Joined:
    Dec 23, 2017
    Posts:
    24
    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)
     
  18. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,788
    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.
     
  19. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,869
    Please don't hijack another person's topic, especially not one that is a year and a half old. Instead make your own... ;)
     
Thread Status:
Not open for further replies.

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