Precise mask - a mysterious collision when rotating an object

Chodec974

Member
Hi, I'm dealing with a mysterious ghost with sprites. I have a spaceship that uses a precision collision mask. I also have three types of asteroids obj_AsterLarge, obj_AsterMedium, obj_AsterSmall, which also use a precision (per frames) collision mask. Each type of asteroid has 4 frames, which I randomly assign when creating an instance.

Everything seems to work flawlessly (left picture), but it doesn't (right picture). For all sprites, there is one specific empty space in the lower left corner that causes a collision with the ship. I originally thought, ha, an unwanted pixel in graphics, but no no. The graphics are fine. Interestingly, all sizes and all asteroid frames do this, a total of 12 (4 frames × 3 objects).

I tried to set the collision as an ellipse. Also tolerance at 128. It didn't help. Always the lower left corner will cause a collision and the ship will explode. Please, do you have advice for me? Thank you.

1631637415092.png
 

Foldup

Member
Unless GameMaker is having a hard time with the precision masks (I guess that's possible) then your collision mask might be wrong.

You might try making a highly visible, solid sprite and use that for the collision mask. That way you can draw it to screen and really see what it's doing. I sometimes use secondary sprites as collision masks instead of having them on the objects themselves.

That's more a troubleshooting / process of elimination thing to make SUPER sure your collision masks are good.
 

TheouAegis

Member
Keep in mind also if you are rotating your ship, which you did in that second picture, the pixels do stretch out I bet, there can even be slightly invisible pixels interfering with the Collision as well. Your ship itself might have a perfect sprite, but once you rotate it, imperfections will arise. You can have it render all objects to a surface ignoring Alpha values and scene if a collision is drawn onto the surface that way. You might also be able to just try tweaking the tolerance settings in the Sprite, maybe you can make it ignore certain pixels based on their opacity.
 

Chodec974

Member
Thank you for the advice. I was looking for a reason why this is happening and in my opinion it is a GM mistake.

I painted a sprite, a green and a red circle, and set it to a precise collision. I assigned the sprite obj_Test, which moves to the mouse cursor so that I can easily search for a place with a collision. Step: if there is a collision with an asteroid, display the red circle, if there is no collision, display the green circle. Everything seems to work precisely until the wheel moves to the position of the lower left corner of the asteroid, where there is empty space, so there should be no collision. I tried to set the Tolerance to 128 (50%), it didn't help, I tried even more, eg 240. Here is the picture. Everything is OK on the left, a collision occurs on the right, where there is empty space. I painted the frame to indicate the rotation of the sprite.
1631691900881.png

Finding! If I turn off the asteroid's rotation, there will be no collision in the lower left corner. How is it possible? All I have to do is randomly rotate the object when Create, the error will appear. I generate a random number for both the rotation and the rotation speed of the asteroid. In Step, rotation is turned off.
1631691970625.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
How are you checking for a collision? Using an event or an action? Also how are you rotating things? Custom value or image_angle? If you aren't using image_angle then the instance isn't rotating, your just drawing the sprite rotated.
 

Chodec974

Member
When creating an instance, I select a random number from 0 to 360 and assign it to image_angle. Next, I select a number from 0.04 to 0.10 in the variable (_rot), then enter this variable in the Step for rotating the object.

1631768066963.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, so, you are NOT using the image_angle variable to rotate the object? If not then there is your problem. Just drawing it rotated means that the collision isn't being rotated along with it. Image_angle controls how the collision mask rotates, so you need to use that variable if you want this kind of precise rotated collisions. Also note that the If Object At PLace action (IIRC) requires that both objects being checked (the one calling the code and the one being checked) have the SAME type of collision mask, ie: they both need to have precise-per-frame checked.
 

Chodec974

Member
Thank you for the advice. I do not attack your words, but unfortunately you are not right. Or am I doing something wrong? From my point of view, this is a GM error.

I have created a new project "TestRotation", which I provide here for download, including the used images, so that you can try and see for yourself the problem. I have the current version of GMS 2.3.4.580.

I created a tricolor triangle and a hexagon, both rotating. Hex has two colors, green and red. In Step, I collided with a triangle. If a collision occurs, Hex turns red. When there is no collision, Hex is green. Both Sprites have a set precision collision (per frames). Hex moves the mouse cursor.

Note that Hex turns red even if no collision occurs. This always happens with the red or purple color of the Triangle. ATTENTION! At a certain angle of the Triangle, everything happens and Hex is green. Test.

1631814191801.png
 

TheouAegis

Member
Does the issue occur even if a sprite has just one subimage?

Does the issue occur even if you use normal Precise collisions rather than Precise Per Frame collisions?
 

Chodec974

Member
I tried everything in my game project. I set the mask on the ellipse, it didn't help. Which is pretty weird. At the same time, I often use collisions during rotation. Only now have I noticed this problem. Please download and try the "TestRotation" project. Easy to see!
https://www.darkbeastgame.com/files/TestRotationGMS2.3.4.580.zip

The collision mask rotates correctly, just as if it had hidden pixels in the lower left corner of the image (mask), where there is otherwise a blank space.
 
Top