0 votes

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.

in Engine by (32 points)
edited by

1 Answer

0 votes

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

by (21,714 points)

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.

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.