Pixel perfect collision x Move and collide
Asked Answered
L

4

0

Hi there!
I'm trying to do a puzzle scene for my 2D game using tilemap for the ground and adding some structures, such as the pillars (Static bodies) and moveable blocks (Kinematic bodies), by using the grid snapping feature and the built-in rules of the editor, so I can have a "perfect pixel" alignment/placement of those items (at least visually).

However, when I tried to push the moveable block (with move_and_collide) it stops on the pillar, even they were aligned to not collide to each other.

There's some way to fix it? Is there any parameter I can change on the static bodies or kinematic bodies to avoid this collision?

Ps. I already tried to fix it using the CollisionPolygon2D instead of the regular Collider2D, but the result was the same.

Any help will be appreciated πŸ™‚

Leotie answered 24/8, 2023 at 21:6 Comment(0)
J
0

a temporary and vague solution would be to put the pillars and blocks in different groups of collision masks(I would tell you a real solution but I'm kind of half, well more like completely stupid), this is being translated sorry for some error in the syntax

Jejunum answered 25/8, 2023 at 1:28 Comment(0)
L
0

Jejunum thanks, dude. πŸ™‚
By adding them on different group of collison masks it will make them not collide at all, right? They should collide, but in a pixel perfect way, so the blocks will be able to pass through some small spaces between 2 pillars or don't stop on the corner of the pillar (as you can see on the figure).
By applying your suggestion, can I have this kind of behavior or the blocks will not collide with the pillars anymore, passing throught them.

Leotie answered 25/8, 2023 at 12:16 Comment(0)
C
0

Leotie it could be that you are using move_and_collide() rather than move_and_slide(). The first method makes it to where when bodies collide, they stop, which is why the crate stop when they touch the pillars. The second will allow them to "slide" against one another. Try that first.

Claude answered 25/8, 2023 at 16:35 Comment(0)
L
0

Claude thanks dude.
Actually I could solve this problem by reducing a little bit the collider size of the moveable block. So it is able to move through the small space between pillars and it doesn't stop after hit the corner of the pillar.
However it was needed to do a small fix on the position of the block after it collides to the pillar. I did it by applying the cell position of the tilemap, that is under the block, to the block. Now it is working perfectly. 😊

Leotie answered 26/8, 2023 at 4:17 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.