• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Bounding Boxes; Distance to object doesn't work on large sprite? [SOLVED]

Dr_Nomz

Member
If I have a large sprite that's 500x500 and it's for a wall, and my player can't roll if the distance to that object is lower than 1 pixel, then I simply won't be able to roll when near it.

But if the sprite is hollow, and I can go into it, even though I'm say 50 pixels away from the visible, collidable edge, I won't be able to roll because the game still thinks I'm closer than 1 pixel to it.

Is there any way to fix this? Could precise sprites ignore this issue? Or do I have to use a different function entirely?
 

Rob

Member
If I have a large sprite that's 500x500 and it's for a wall, and my player can't roll if the distance to that object is lower than 1 pixel, then I simply won't be able to roll when near it.

But if the sprite is hollow, and I can go into it, even though I'm say 50 pixels away from the visible, collidable edge, I won't be able to roll because the game still thinks I'm closer than 1 pixel to it.

Is there any way to fix this? Could precise sprites ignore this issue? Or do I have to use a different function entirely?
Can you spend another 10-15 minutes thinking about the question you're asking? It will probably help you just as much as the people trying to answer it.
 

Dr_Nomz

Member
Well, for example, here I'm more than a pixel away from the wall, so I can roll by pressing Space.


If I were right up against it, I wouldn't be able to do this, since I'd be closer than 1 pixel to it.


But here I can't roll because these particular "walls" are actually one really big sprite. So even though I'm far enough away from the collidable walls I can't roll, even though I can still walk in between them.

Code:
distance_to_object(obj_Wall)>1
That's the check I'm using to make sure the player is at least 1 pixel away from the wall before rolling.
 

TheouAegis

Member
Wait, so each of those blocks are actually all part of the same sprite, so you have just one wall object and it has all of those walls as its one sprite? If that's the case, then you'd need to use precise collisions.
 

Dr_Nomz

Member
It IS a precise sprite, but distance_to_object still thinks it's closer than on pixel. Any idea why that is?
 
It IS a precise sprite, but distance_to_object still thinks it's closer than on pixel. Any idea why that is?
Probably because you are inside the object and that would constitute a negative distance (or it gets clamped to 0)? Therefore anything inside the object is < 1 pixel away from it.
A simple test would be to display that value on your hud or through using show_debug_message so you can see it changing as you get closer and then confirm whether it is in fact a negative number once you go inside the whole wall object.
You probably will end up not using the distance_to_object function as that obviously cannot handle what you are trying to do, and maybe you have to go through some of the other collision functions to see if they give you something equivalent to what you need.
 

Simon Gust

Member
distance to object is (like any other distance function) vector based and cannot result in negative distances, additionally it will give you the closest distance from the nearest bounding box of the caller to the nearest bounding box of the receiver. A precise sprite doesn't not have it's bounding boxes adjusted and they will remain rectangular.
 

TheouAegis

Member
I just tested. distance_to_object() only takes the bounding box coordinates as defined by the sprite. Precision doesn't affect the bounding box, so you could even set the default bounding box values to (0,0,0,0) and GM will always assume the sprite is 1 pixel in dimension regardless of precision when using distance_to_object().
 
Last edited:

Dr_Nomz

Member
Do you have any suggestions for something that works like distance to object, but works on precise sprites?
 

Dr_Nomz

Member
Man collision_circle works AWESOME for this, I think it might just be better than point_distance, thank you! (Also using circle because my sprite is a circle)
 
Top