GML How to set place_meeting for a specific "x" and any "y"?

M

Mobie

Guest
I need to set up a place_meeting that will occur at any y position on the screen. So how do I code this, for example:

if place_meeting(x,??,obj_SomeObject)

For the ?? in the above, how do I tell GM to use all y coordinates. So anywhere, up or down, the place_meeting will trigger?
 
Last edited by a moderator:

TheouAegis

Member
Use a loop starting from sprite_height until room_height

But you said you wanted everything, so you would need to use a with all Loop. Personally I wouldn't even use place_meeting, just compare the left and right bounding box of values.

with all if bbox_left<=other.bbox_right && bbox_right >= other.bboxfleft {
 

samspade

Member
I need to set up a place_meeting that will occur at any y position on the screen. So how do I code this, for example:

if place_meeting(x,??,obj_SomeObject)

For the ?? in the above, how do I tell GM to use all y coordinates. So anywhere, up or down, the place_meeting will trigger?
I think it would be easier to answer this question if we knew what you wanted to do this for as it doesn't make a whole lot of sense. As TheouAegis pointed out you could just put in a loop of some kind. For example:

Code:
for (var i = 0; i < room_height; i ++) {
    if (place_meeting(x, i, object)) {
        /* do something */
        break;  
    }
}
But this doesn't seem very efficient. Checking bounding boxes seems like a better idea.
 

2Dcube

Member
place_meeting checks for a collision at a point.
Maybe use "collision_line" ?

if collision_line(x, 0, x, room_height, obj_SomeObject, false, false)

This would check for a collision on a vertical line from top to bottom of the room.
 
If you do use collision_line, bear in mind it only returns the first instance found, and it may not be the closest / most relevant instance.

There is a collision_line_all script on gmlscripts.com that can return all instances colliding with the line.
 
M

Mobie

Guest
If you do use collision_line, bear in mind it only returns the first instance found, and it may not be the closest / most relevant instance.

There is a collision_line_all script on gmlscripts.com that can return all instances colliding with the line.
Use a loop starting from sprite_height until room_height
{
I think it would be easier to answer this question if we knew what you wanted to do this for as it doesn't make a .
place_meeting checks for a collision at a point.
Maybe use "collision_line" ?

.
Thanks for your answers!!

Clarification: This is an endless runner, horizontal scrolling game. I need a text to appear when a player is a certain x distance away from an object. The player's y moves all up and down the screen and I'm having trouble with the player missing the place_meeting because he is too high or too low. So even if he is way above it, I want the place_meeting to return true when the player is a certain x away.

Does that make my question more clear?
 
Last edited by a moderator:
E

Edmanbosch

Guest
Clarification: This is an endless runner, horizontal scrolling game. I need a text to appear when a player is a certain x distance away from an object. The player's y moves all up and down the screen and I'm having trouble with the player missing the place_meeting because he is too high or too low. So even if he is way above it, I want the place_meeting to return true when the player is a certain x away.
I think you'd probably want to use something like distance_to_object/distance_to_point or something else meant to calculate distance.
 

Smiechu

Member
Ahh, so don't use "place_meeting" at all. That makes sense. I'm going to give that a go. Thanks!
Yes...
Other way... if you need to do samething after the player passed the object...
Do a line colission in player x...
and trigger a alarm... If you know the speed and and framreate, you can calulate the proper alarm value...
 
Top