Skip to content

Instantly share code, notes, and snippets.

Last active Jan 16, 2019
What would you like to do?
Godot Tilemap Collision (for detecting the exact colliding cell from the player position)
func _physics_process(delta):
var direction = Vector2()
# .. figure out the direction
var collision = move_and_collide(direction)
if collision:
func handle_collision(node):
var collider = get_collider()
if collider is TileMap:
var col_cell = Vector2()
# from player position do we add/subtract a cell on the x axis
if node.position.x > position.x:
col_cell.x += 1
elif node.position.x < position.x:
col_cell.x -= 1
# or the y axis
if node.position.y > position.y:
col_cell.y += 1
elif node.position.x < position.y:
col_cell.y -= 1
var loc = collider.world_to_map(collider.to_local(position))
loc += col_cell
var cell = collider.get_cellv(loc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment