GameMaker Instance_nearest returning the wrong platform

Y

Yelf

Guest
The issue can be seen in this video: LINK
(Also if you have better ways to link videos please tell me)
I have code that makes the instance_nearest platform visible.

Essentially my platform collision uses the closest platform, but since its returning the wrong platform it isn't working.
Finding closest platform:
GML:
var currentPlatform = instance_nearest(x,bbox_bottom,obj_platform);
Collision code snippet:
Code:
if (fall < 0 && (place_meeting(bbox_left, bbox_bottom,currentPlatform) || place_meeting(bbox_right, bbox_bottom,currentPlatform) || place_meeting(x_center, bbox_bottom,currentPlatform)))
    {
        v_speed = 0;
        y = currentPlatform.bbox_top - 44;
    }

Additionally, everything works if the platforms are laid out differently.
This layout causes a problem:
doesnt.PNG

But this layout works perfectly:
Works.PNG

Please ask if you need any additional info.
Any help is appreciated :)
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
The linked video requires permission to watch. We don't have this permission.

I suggest uploading it to Youtube and then embedding it here (just pasting the link will auto-embed it).
 
Y

Yelf

Guest
Sorry about that, should be fixed now.
I'll post the link here too:
 

TsukaYuriko

☄️
Forum Staff
Moderator
Depending on where those platforms have their origin, the upper one may very well be considered closer to the player than the lower one past the half-way mark in one way or the other - is there a specific reason why you want to check collisions only for the nearest platform? I'd suspect it's for the sake of performance, though I'd dare to question whether it's actually more efficient to run n distance checks and one rectangle check rather than n rectangle checks in that case.
 

TheouAegis

Member
You scaled that rectangle, didn't you? Try keeping everything with a 1:1 scale and see if the issue still happens. I doubt it will occur when scaling is left intact.
 
Y

Yelf

Guest
The reason I used a nearest platform system is because it would teleport me to the y level of the oldest obj_platform upon landing on any platform. Is there a way to change that?

You scaled that rectangle, didn't you? Try keeping everything with a 1:1 scale and see if the issue still happens. I doubt it will occur when scaling is left intact.
If I use single platform objects unscaled, the game plays the falling animation when I move in certain directions, but the original problem isn't present

Depending on where those platforms have their origin, the upper one may very well be considered closer to the player than the lower one past the half-way mark in one way or the other - is there a specific reason why you want to check collisions only for the nearest platform? I'd suspect it's for the sake of performance, though I'd dare to question whether it's actually more efficient to run n distance checks and one rectangle check rather than n rectangle checks in that case.
I assume what you're saying is that instance_nearest uses the objects origin, is there a method that will take any part of the bounding box?
 

TheouAegis

Member
collision_line(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1,obj_platform,0,0)

it would teleport me to the y level of the oldest obj_platform upon landing on any platform
Sounds like you did
Code:
if place_meeting(x,y+vspd,obj_platform) 
    y = obj_platform.y;
The correct code would have been
Code:
with instance_place(x,y+vspd, obj_platform)
    other.y = y;
 
Y

Yelf

Guest
collision_line(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1,obj_platform,0,0)
This works from what I can tell, thanks!
For some reason the code you typed didn't show up in your comment for me, I only saw it when I tried to reply. I'm not using either of those systems, but that could be a separate problem I have, which I'll try fixing now that this should work
 
Top