GameMaker [Solved]Check distance beneath instance

Ladi_Pix3l

Member
I'm using this code...
Code:
if (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    //Do something
}
to basically have my enemy activate with in range but I only want it to activate if the player is below the enemy.
I tried adding a variable to the y1 but my guess that it won't work to my advantage. I want the enemy to activate no matter how far below the player is from the enemy.

Is there someway I can do this? I guess checking between 2 points would be my option, but how?
 

jo-thijs

Member
I'm using this code...
Code:
if (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    //Do something
}
to basically have my enemy activate with in range but I only want it to activate if the player is below the enemy.
I tried adding a variable to the y1 but my guess that it won't work to my advantage. I want the enemy to activate no matter how far below the player is from the enemy.

Is there someway I can do this? I guess checking between 2 points would be my option, but how?
Like so?
Code:
if (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30 && y > oPlayerParent.y)
{
    //Do something
}
 

Ladi_Pix3l

Member
WAIT. . WTF I thought I tried this. . .Hold a tic. . .

EDIT: Okay I do remember trying this but it gave me the same results and only activating at the enemy's y level. if I'm 50, 60 70, etc pixels below it it doesn't activate.
 
Last edited:

jo-thijs

Member
WAIT. . WTF I thought I tried this. . .Hold a tic. . .

EDIT: Okay I do remember trying this but it gave me the same results and only activating at the enemy's y level. if I'm 50, 60 70, etc pixels below it it doesn't activate.
Similar to how a thwomp works in Super Mario
Oh, so not in a circle, but in a rectangle instead?
Then do something like:
Code:
if (abs(x - oPlayerParent.x) < 30 && y > oPlayerParent.y)
{
    //Do something
}
 

Ladi_Pix3l

Member
So didn't actually work at all actually. I looked up what abs was though and got an idea what you guys were trying to show me. Unfortunately the results ended the same.
the object activates from 30 pixels within in range via x value. but not with it being under the enemy. . . I think I'm missing something
 

Ladi_Pix3l

Member
Okay I figured it out.

Apparently I had to check for the y position, then check for the point distance.
Like So...
Code:
if (y+20 < oPlayerParent.y) && (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    //Do something
}
That was silly

Thanks for the help guys <3
 
W

Wraithious

Guest
I'm using this code...
Code:
if (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    //Do something
}
to basically have my enemy activate with in range but I only want it to activate if the player is below the enemy.
I tried adding a variable to the y1 but my guess that it won't work to my advantage. I want the enemy to activate no matter how far below the player is from the enemy.

Is there someway I can do this? I guess checking between 2 points would be my option, but how?
I think all that's missing is the x values, so you could do
Code:
if (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    If (x-100 > oPlayer.x && x+100 < oPlayer.x) {
            //Do something
    }
}
This way gives you a range you can use some AI with by changing the values of the x checks (instead of 100 put a variable there i stead), as the oPlayerParent gets smarter the range can first narrow, then shift according to oPlayers direction etc
 
Last edited by a moderator:

jo-thijs

Member
So didn't actually work at all actually. I looked up what abs was though and got an idea what you guys were trying to show me. Unfortunately the results ended the same.
the object activates from 30 pixels within in range via x value. but not with it being under the enemy. . . I think I'm missing something
Okay I figured it out.

Apparently I had to check for the y position, then check for the point distance.
Like So...
Code:
if (y+20 < oPlayerParent.y) && (point_distance(x,y,oPlayerParent.x,oPlayerParent.y) < 30)
{
    //Do something
}
That was silly

Thanks for the help guys <3
No, the order in which you check the conditions doesn't matter.

What is actually different, is that I previously suggested "y > oPlayerParent.y" instead of "y < oPlayerParent.y",
because I misread your post (ven though I should have known, based on the thwomp example).
I guess noobhere did the same thing.
 
Top