Animating tile when collision occurs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ryugomez

I’m using KinematicBody2D for the player. I want to get the tile I’m colliding with so that I could change its animation. My tileset has sprites and animated sprites in it.

:bust_in_silhouette: Reply From: kidscancode

This is a very common question. So common, in fact, that I recently posted a video/project to show how to do it.

The video: https://youtu.be/OzgK__VowVs

The project: https://github.com/kidscancode/godot_one_shots/tree/master/tilemap_collision

But those are only for sprites. I want my tileset to have animated tiles too, but when I had it converted, the newly added animated spritesheet tile didn’t show up.

ryugomez | 2019-01-06 06:17

What I really want specifically is when the player collides with the tile, it will be animated. If the player doesn’t, it would come back to idle.

ryugomez | 2019-01-06 06:21

Your question was about detecting which tile was collided. That does not have anything to do with whether you’re animating the tile’s texture or not.

You may be misunderstanding how TileMap works. The tiles of a TileMap are not Sprites. You can use Sprites as helpers when you make your TileSet, but when you convert to TileSet, it only contains texture and collider information. This data is then used by the TileMap to batch drawing and collision. That is why, as in the above example, the collision detects the TileMap as a whole.

As for animation, TileMap does not support animated tiles. You can work around this using shaders or AnimationPlayer to modify the TileSet textures at runtime, but this can be a cumbersome process (I have a tutorial on this as well). Note: animated tiles will be supported in the upcoming 3.1 release.

kidscancode | 2019-01-06 06:24