Hi, I’m a Godot beginner and I’m developing a 2D platformer. I’m currently trying to implement a projectile, a spear. The idea is for it to collide with the wall and create a platform. The problem is that when it collides with the ground, it also creates a platform. I tried using TileData to place a String in the block corresponding to the wall in the tilemap layer and thus try to create a detection for the spear, but I’m having trouble implementing it and I don’t even know if my idea makes sense. Do you have any guidance on how to do this?
Godot Version
Replace this line with your Godot version
Question
Ask your question here! Try to give as many details as possible
1 Like
To get custom data from a TileMapLayer collision you have to find the tile, if you are using a CharacterBody2D for the spear you could check on move_and_collide
var collision := move_and_collide(velocity * delta)
if collision:
var tilemap := collision.get_collider() as TileMapLayer
if tilemap:
var tile_coords := tilemap.get_coords_for_body_rid(collision.get_collider_rid())
var tile_data := tilemap.get_cell_tile_data(tile_coords)
if tile_data and tile_data.get_custom_data("Wall") == "Wall": # or use a boolean custom data
make_platform()
If you do not want to assign “Wall” custom data to each wall you could use the collision normal instead.
var collision := move_and_collide(velocity * delta)
if collision:
var dotup: float = collision.get_normal().dot(Vector2.UP)
if absf(dotup) < 0.001: # or adjust 0.001 to the maximum wall angle
make_platform()
2 Likes
Thanks for the reply, I’m using a 2D Area for the spear, would that change the approach? I adjusted the Tilemap text to better match the sides.