Legacy GM Collision not working when flipping x [SOLVED]

L

lelo9444

Guest
I'm working on a 2d platformer that has slopes. A problem I have stumbled into is that while normal slopes work fine with what I have when I flip them over in the Room Editor their collision box gets jumbled up. My current code checks for a 1 pixel space above a pixel to see if it can place the player there when they move into a slope. The problem is the flipped slopes seem to ignore their first pixel for some reason (thus making them start with a two pixel height).
I could easily fix this by making more objects for the opposite slopes but I would prefer to know why this happens first and if I can solve it.
(I'm 99% sure the problem is that the flipped slope starts with a 2 pixel height as it ignores the first pixel of the 45 degree slope, I have checked the code multiple times and I have even seen the faulty hitbox in the game)
 
L

lelo9444

Guest
Here are some images showcasing the problem

Screenshot_4.pngHere you can see where the slope begins (The slopes hitbox is set to precise so the whole sprite should be the hitbox)
Screenshot_5.png In this image, you can see how the player sprite is intersecting with the first pixel of the slope thus making a 2 pixel high obstacle.
 
P

Pyxus

Guest
Here are some images showcasing the problem

View attachment 22135Here you can see where the slope begins (The slopes hitbox is set to precise so the whole sprite should be the hitbox)
View attachment 22136 In this image, you can see how the player sprite is intersecting with the first pixel of the slope thus making a 2 pixel high obstacle.
Is your collision mask set to "same as sprite"? If so try choosing a specific sprite and observe the collision behavior.
 
L

lelo9444

Guest
Is your collision mask set to "same as sprite"? If so try choosing a specific sprite and observe the collision behavior.
I'm working with this collision mask at the moment, what do you suggest I do?
Screenshot_6.png
 
P

Pyxus

Guest
I'm working with this collision mask at the moment, what do you suggest I do?
View attachment 22166
Sorry, I should have clarified, I mean in the object you're given the option to set the mask. It defaults to "same as sprite", however when you deform the sprite by changing its image size or angle it often screws with the collision. So I'm suggesting you change the mask to something else rather than "same as sprite" as a test. Then check to see if the collisions are behaving as they should.
 
Last edited by a moderator:
L

lelo9444

Guest
Sorry, I should have clarified, I mean in the object you're given the option to set the mask. It defaults to "same as sprite", however when you deform the sprite by changing its image size or angle it often screws with the collision. So I'm suggesting you change the mask to something else rather than "same as sprite" as a test. Then check to see if the collisions are behaving as they should.
Ah, I see. I tried changing the mask to a solid object and there was no clipping, so it seems to only happen when the mask is the same as the sprite. (I also made another sprite for a left slope just in case I couldn't figure this out and when I used that one as a mask the player also clipped into it)
 

TheouAegis

Member
The reason is because images flip around the origin. So with image_xscale of 1, it's all within sprite_width-1 of the image. When you flip it, it's no longer in the confines of the sprite width.
 
L

lelo9444

Guest
The reason is because images flip around the origin. So with image_xscale of 1, it's all within sprite_width-1 of the image. When you flip it, it's no longer in the confines of the sprite width.
Oh alright, does it not have a solution then?
 

HayManMarc

Member
I think you would either need to change the origin coordinates when you flipped the sprite, or set the sprite one pixel over (to the left?) when placing it (when it's flipped).
Code:
Draw Event:
if image_xscale = -1
{
draw_sprite_ext(sprite_index, image_index, x - 1, y, ....etc
}
else
{
draw_self();
}
Or, maybe, make a sprite that will have the same origin when it's flipped, which would be a sprite 31px wide (or 33px).

I think. Not sure about that last suggestion.
 
Last edited:

HayManMarc

Member
Nope. Just thinking about it and I don't think that code will work. Need to move the sprite instance over one pixel. Might need to make different masks and swap them out accordingly.

Sorry if I made a mess of things. Just ignore me.
 
L

lelo9444

Guest
Alright, I managed to fix the issue by adding a 1 pixel trim to the sprite and offsetting the center to compensate.
 
Top