[Solved] place_meeting point detections not functioning

Discussion in 'Programming' started by Sargonnas, Apr 15, 2019.

  1. Sargonnas

    Sargonnas Member

    Joined:
    Apr 15, 2019
    Posts:
    3
    Hello! First post here, I apologize of I'm too long-winded or don't know what pertinent information to give. I am not a programmer by nature.

    I've followed Shaun Spaulding's complete platformer tutorial as a primer, so if some of his variables look familiar that's why. I've been chewing on this problem off and on for about a month, moving onto different issues, moving back, approaching it differently. It has yet to work out so I'm finally reaching out.

    I've got objects called oWall which block movement etc. They function perfectly in all directions to block the player, bullets, etc.

    My problem is detection. I have a toe point and a reach point that are drawn correctly in front of the character, so their positions appear to be accurate. HOWEVER. When I display whether or not the toe and reach points are colliding with oWalls the answer seems to be "almost always".

    In the player end_step I've got this:
    Code:
     
    // test to see if a block is in front of your feet
    if facing == 0
    {
       if (place_meeting(toe_x,toe_y,oWall)) block_at_feet = "yes";
       if (!place_meeting(toe_x,toe_y,oWall)) block_at_feet = "no";
    }
    if facing == 1
    {
       if (place_meeting(toe_x,toe_y,oWall)) block_at_feet = "yes";
       if (!place_meeting(toe_x,toe_y,oWall)) block_at_feet = "no";
    //   draw_circle(x+1,y+34,10,1);
    }
    
    // test to see if a block is in front of your chest (climbing height)
    if facing == 0
    {
       if (place_meeting(reach_x,reach_y,oWall)) block_at_chest = "yes";
       if (!place_meeting(reach_x,reach_y,oWall)) block_at_chest = "no";
    }
    if facing == 1
    {
       if (place_meeting(reach_x,reach_y,oWall)) block_at_chest = "yes";
       if (!place_meeting(reach_x,reach_y,oWall)) block_at_chest = "no";
    }
    
    Later down in the code (after actually moving the character, detecting collisions etc) I have the following:
    Code:
    // Update centerpoint
    center_x = x + sprite_width * 0.5;
    center_y = y + sprite_width * 0.5;
    if action == "crouch" or action == "crawl" center_y += 16;
    if facing == 1 && action == "crawl" center_x += 12;
    if facing == 0 && action == "crawl" center_x -= 12;
    
    //Update Toe and Reach points
    toe_y = y+60
    reach_y = center_y;
    if facing == 1
    {
       toe_x = x+35;
       reach_x = x+35;
    }
    if facing == 0
    {
       toe_x = x+17;
       reach_x = x+17;
    }
    
    It may be worth noting that moving the first bit of code down to directly above the second seems to have no impact. I don't want to put the code there because I want a section in between the two to have logic for initiating climbing and crawling based on the collisions detected.

    IDE v2.2.2.413
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,692
    Those are the wrong functions. You want position_meeting. place_meeting uses the objects collision mask as defined from its origin point and x and y you give the function. Your code was basically asking it whether there was a collision with your sprite, if your sprite was at that position - which would probably be the case assuming you sprite's mask was bigger than a few pixels.
     
  3. Sargonnas

    Sargonnas Member

    Joined:
    Apr 15, 2019
    Posts:
    3
    Oh yee coding angel I thank you!
     
    samspade likes this.
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,858

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