Move a TileMap like a CharacterBody2D

Godot Version

4.3.stable

Question

In my game I have a moving spaceship (a TileMapLayer), it has use_kinematic_bodies enabled to act as a moving platform for the players.

But when moving it by hand like this:

func _physics_process(delta: float) -> void:
    position.y += 20 * delta

the TileMap passes through the floor (another TileMapLayer, tried with and without use_kinematic_bodies).

TileMapLayer clipping

I tried setting the ship as a child of a CharacterBody2D or creating individual shapes for each tile, but none of my attempts worked.

Is there any way to make the TileMap act effectively as a CharacterBody2D, so as not to move if there are obstacles in its way?

I have the same problem, did you find a solution? Because I did, but I don’t like the implementation.

1 Like

Sadly no, I couldn’t manage to make the TileMap move while still acting as a platform for the player and colliding with another TileMap.
I believe it is just a quirk of the physics engine. Since then, though, I have tried with a different physics engine and got better results with a different project. Maybe that will work for you.

Well if you want to have CharacterBody2D behavior, have you tried starting with a CharacterBody2D node and then making the TileMap a child of that?