Physics Collision Masks Off By One Pixel

***
Update 7/13/21

I received an email from Yoyo's support team. They've identified this issue as a glitch and it will be addressed in a future update.
***


Hi everyone. I sent this to YoYo more than a week ago and I haven't gotten a response. I'm assuming it's a glitch but I guess I could be doing something wrong.

The issue: physics collision masks are offset from the sprite by +1 pixel in both x and y. Doesn't matter if you use the built in editor or create the fixure in code, though if you create a box fixture through code it will only be offset by half a pixel.

Hopefully someone can tell me if I'm doing something wrong.

Thanks in advance if you try to help.

 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
OKay, a couple of things to note here... First, the physics collision mask is set to the HALF width and HALF height of an object. You can't get half a pixel, so the code has to try and place it as close as possible using an integer position, which is probably what is resulting in the offset. Have you tested using something a little larger than a pixel? And preferably with an even width/height? Having an odd number means that you are forcing the physics engine and the graphics pipeline to "choose" a pixel position since you can't draw half a pixel either. I certainly don't think that there is anything too weird in this yet, as I feel that your example is flawed by being 1px in size.
 
I caught this because I noticed the physics masks were off on a bunch of 16x16 squares and a small circle. I also created some polygons through code and they were all off by one. I can post examples this evening.
 
The single pixel in this image has a top-left sprite origin. I understand that testing with a single pixel may cause an issue. The other two boxes in the image have middle-center sprite origins, and it doesn't make a difference. Just in case, I also tried changing the origins after this test to top-left. All it did was reposition the objects in the room. Their masks continued to be one pixel off. @Nocturne you were right that using a single pixel for the example was a little flawed. Using code to recreate the box fixtures had the exact same results for the 2x2 and 16x16 boxes, no changes from using the built-in collision shape editor. Using code to set a box shape on a 1x1 box does offset it by .5 pixels instead of 1. It ends up looking like a scaled down version of the 2x2 box.

This is driving me a little nuts. I know the physics engine isn't heavily used but it seems like anyone who currently uses it would have seen this.


Screenshot 2021-06-28 210605.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Interesting, and thank you very much for doing some more thorough testing. I have used the physics system a LOT but never usually on anything that would require a precise bounding box or pixel perfect alignment... and I suspect that this is the same for most users. Either that or they've simply shrugged it off as a quirk of the system and just offset their fixtures by 1! My suggestion would be to create a YYZ of your test program and file a bug with YYG about it. I can't really see any reason why this wouldn't be considered a bug and something that should be fixed...
 

Roldy

Member
It is definitely a bug. Especially when you look at sprites with odd number of pixels.

Setting the collision shape through the editor the physics fixture will actually be off by 2 pixels in both directions for an odd width/height sprite. But to get it lined up you have to only move it back (-1, -1). The same shape setup through code will be off by 1 pixel in both directions and to get it lined up it has to be offset (-0.5, -0.5).

It is easy to work around if you know about it, but it should be fixed.

Example:

1624954137000.png

This is an object with an 11x11 sprite. A fixture is attached via the editor and also through code. The one attached through the editor is off by two pixels, the one through code is off by one pixel.
 

Slyddar

Member
Hopefully someone can tell me if I'm doing something wrong.
Nope, everything checks out, and even after some testing myself I agree with your analysis. You've already logged a problem, but maybe send them the link to this post too, as it definitely is a problem.
 
Nope, everything checks out, and even after some testing myself I agree with your analysis. You've already logged a problem, but maybe send them the link to this post too, as it definitely is a problem.
Will do. I'll update this thread if I get a response.
 

badwrong

Member
I know this is a very old thread I'm bumping, but the issue still exists.

Also, the suggested fixes from @Roldy do not actually work:

Setting the collision shape through the editor the physics fixture will actually be off by 2 pixels in both directions for an odd width/height sprite. But to get it lined up you have to only move it back (-1, -1). The same shape setup through code will be off by 1 pixel in both directions and to get it lined up it has to be offset (-0.5, -0.5).
If the object is axis-aligned then you can get things to line up. However, after any rotation the fixture alignment will be off.

The problem is rather obvious though. Pixels on a sprite are in integers with the upper-left being the origin (of an actual pixel). So, the fixture will essentially rotate around the single pixel at its center of mass and always go in and out of alignment.

Certainly a bug needing fixed after so many years?
 

Zeth_Aran

Member
Bumping the thread again.

I have a project that relies pretty heavily on the physics engine and if I can’t find a solution to this I’m not sure what else to do.
 

Zeth_Aran

Member
Well I have some good news! And if possible, idk how likely, but if a dev sees this, could they give an update?

I was going to report the bug again, but it looks like its apart of their headline issues tab, and they are aware of it! Great to see!

However, it has been 2 years since the original post, and I'm afraid this is nothing but buzz. So could a dev actually say if there has been any progress on this? If this remains broken, as I continue to work on my vertical slice I'm seriously afraid I'll need to switch engines/IDEs..... I've been a gamemaker fan since like 2017, it would suck to have to say goodbye, but this is a going to be a long term project and I need this working or the whole premise is bust.
 

Attachments

ReignOnU

Member
I noticed this as well. Will it ever get fixed?

but this is a going to be a long term project and I need this working or the whole premise is bust.
Its not that difficult to fix, you can adjust your sprite or something.
 
Well I have some good news! And if possible, idk how likely, but if a dev sees this, could they give an update?

I was going to report the bug again, but it looks like its apart of their headline issues tab, and they are aware of it! Great to see!

However, it has been 2 years since the original post, and I'm afraid this is nothing but buzz. So could a dev actually say if there has been any progress on this? If this remains broken, as I continue to work on my vertical slice I'm seriously afraid I'll need to switch engines/IDEs..... I've been a gamemaker fan since like 2017, it would suck to have to say goodbye, but this is a going to be a long term project and I need this working or the whole premise is bust.
This is a community run forum so you shouldn’t have any expectation that the devs will even see posts. Occasionally you might get lucky and someone on the yoyo team will respond, but there’s no guarantee or even likelihood of that happening.
 
Top