Tilemap collisions are off on y-axis?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Benjamin Stammen
:warning: Old Version Published before Godot 3 was released.

I’ve been learning the engine through a few videos, and I’m trying to get a basic tile-based project to work. I think I’m understanding the tile grids and how to use them, but I’m experiencing some odd collisions when debugging the same. The horizontal collisions are fine as shown here, i.e., the character is flush against the wall: https://drive.google.com/file/d/0B1Lai8z7Tbi_R2wzTy1qbDBvbDQ/view?usp=sharing
but vertical collisions are off - it’s as though the collision shape was shifted: https://drive.google.com/file/d/0B1Lai8z7Tbi_TVJfWUpqUEJ0VGc/view?usp=sharing, https://drive.google.com/file/d/0B1Lai8z7Tbi_dzVEemZVN000bWc/view?usp=sharing.

The wall should have a collision area of 32x32 on the bottom of each sprite, as should the player:

wall: https://drive.google.com/file/d/0B1Lai8z7Tbi_RjRWNFpiekQ3bEU/view?usp=sharing
player: https://drive.google.com/file/d/0B1Lai8z7Tbi_M1AtNHd5VlFzSHc/view?usp=sharing

What is causing this to be off? I’d appreciate any help!

:bust_in_silhouette: Reply From: Aquiles

Hi! Benjamin Stammen.

Try to resize the CollisionShape of the wall, a full size and try again.

At the top of Godot, there is an option that will allow you to see the Collision Shape when you run your game

There you will see what happens with the Collision Box.

Thanks for the tip about showing collisions! I get something like the below image: https://drive.google.com/file/d/0B1Lai8z7Tbi_QzNJMEJiZjQwUms/view?usp=sharing.

So it looks like the collision area of the tile is being shifted down the y axis by 16 pixels for some reason. Does it have something to do with the conversion to a tile? The player isn’t affected, so I looked into some tile map properties to no effect.

Any more ideas?

Benjamin Stammen | 2017-01-18 00:44

I think that having a Collision Shape of 16px by 16px change it to 16px wide by 32px high, from the size of your sprite (tile), if your sprite is a rectangle the Collision Shape should also be a rectangle and not a square.

Try to do that and tell me.

Aquiles | 2017-01-18 01:55

Alright, so I adjusted it to the size of the sprite (32x64), and it fills the entire sprite. Unfortunately, I really only want half of the wall to be collidable in order to let the player be blocked partially by the front walls. Essentially, I need to figure out how to make the collision area of the walls in the world to be the same as when they’re in the file.

I’m going to keep trying to find new ways to shift the collision area down.

EDIT: it also seems as though changing the collision area’s position and exporting it to a tileset again doesn’t change anything. It seems like tiles just don’t take its original position into account.

Benjamin Stammen | 2017-01-18 04:07

:bust_in_silhouette: Reply From: Benjamin Stammen

Not sure if this is best practice or not, but I ended up opening the converted tileset and using the inspector to plug in offsets that worked for me! Then any map that uses that tile should use it as intended. The offset tools are pretty comprehensive.

:bust_in_silhouette: Reply From: eons

For what I saw on an image, it seems related to the use of CollisionShape2D (I know it has some problems but I have never seen this bug).

Try with CollisionPolygon2D instead when making the tileset scene.

When using CollisionPolygon2D, it actually does align correctly for me! Maybe it’s because I fiddled with something in the meantime, but it seems surprising that the more general polygon model would work but not the more specific sub-case of the rectangle collider.

Thanks so much!

Benjamin Stammen | 2017-01-18 21:14

Is similar to this old bug, no idea if the problem is in the exporter or the tileset when loads it:
Shape offset on tileset · Issue #2231 · godotengine/godot · GitHub

Here is another, more detailed on the CollisionShape2D issue:
CollisionShape2D not work in tilemap · Issue #3503 · godotengine/godot · GitHub

eons | 2017-01-18 22:20

Oh, wow, that sounds exactly like my problem. Thanks!

Benjamin Stammen | 2017-01-18 23:38