GameMaker How to Draw a "point_in_rectangle();" Check [SOLVED]

This question might seem a little too obvious but, I'm using a point_in_rectangle(); to check for collision when the player walks up to an NPC to start a dialog with. The problem is, the player can only activate the dialog when they are above the NPC. This is on a 4-way movement style game by the way. The player can't activate the dialog when they're on the left, right or bottom of the NPC.

What I'm trying to do is, draw exactly where the point_in_rectangle is so I can adjust it. But when I try to draw it using draw_rectangle(); it doesn't line up with the point_in_rectangle();

How can I do this?

Here are the coordinates and some code:
Code:
point_in_rectangle(o_player.x, o_player.y-10, o_player.x-15, o_player.y-28, o_player.x+15, o_player.y+28)
and here is the Step Event calling the code portion. (There is a ton more code by the way)
Code:
if !instance_exists(o_player) {
    exit;
}

var dr = detection_radius;
if(point_in_rectangle(o_player.x, o_player.y, o_player.x-20, o_player.y-20, o_player.x+20, o_player.y+20)) {
    if(myTextbox != noone){
        if(!instance_exists(myTextbox)){ myTextbox = noone; exit; }
    }
    //if I haven't already created my textbox, make one:
    else if(o_input.action_four_pressed_){
        if(instance_exists(obj_textbox)){ exit; }    //exit if a textbox already exists
        event_user(0);                                //if you need variables to update for text
            
        //Hand over variables
        create_dialogue(myText, mySpeaker, myEffects, myTextSpeed, myTypes, myNextLine, myScripts, myTextCol, myEmotion, myEmote);
    }
} else {    //if player moves outside of detection radius
    if(myTextbox != noone){
        with(myTextbox) instance_destroy();
        myTextbox = noone;
    }
}
I've also tried other collision and point methods but they don't seem to work or they activate the dialog of an NPC near the other side of the room.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
draw_point the first two arguments, draw_rectangle for the rest.
I can inform you in advance that you probably don't want o_player.* for rectangle bounds arguments.
 
draw_point the first two arguments, draw_rectangle for the rest.
I can inform you in advance that you probably don't want o_player.* for rectangle bounds arguments.
Oh yeah, that was a typo in the code I posted. I'm not using o_player for the bounds. I've been testing out your suggestion and it's working so far. But, where is the rectangle drawn from when using the point_in_rectangle(); ?
Is it drawn from the "point" (first 2 arguments) in the point_in_rectangle(o_player.x, o_player.y-10, x-20, y-20, x+20, y+20); ? Because I want the rectangle drawn at the center of the o_player.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
But, where is the rectangle drawn from when using the point_in_rectangle(); ?
Is it drawn from the "point" (first 2 arguments) in the point_in_rectangle(o_player.x, o_player.y-10, x-20, y-20, x+20, y+20); ? Because I want the rectangle drawn at the center of the o_player.
Same as for point_in_rectangle, the rectangle is defined by two (top-left, bottom-right) points
 
Same as for point_in_rectangle, the rectangle is defined by two (top-left, bottom-right) points
Ok, so when using the point_in_rectangle(); the "point" is what is checking the collision right? Since the dialog only activates near the "point". Because I thought the rectangle is supposed to check for the collision all around the player.
 

NightFrost

Member
The point_in_rectangle command answers the question "is the given point within the given rectangle" so yes, you can think of the point as a collider and the rectangle as a collision mask.
 
Top