GMS 2.3+ 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.
 
Top