Created
January 3, 2020 12:16
-
-
Save payload/71151e0612414a79d6f914617fda12d1 to your computer and use it in GitHub Desktop.
Godot 3.2 - Area2D collides with TileMap cells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area2D | |
func _ready(): | |
connect("area_shape_entered", self, "area_shape_entered") | |
func area_shape_entered(area_id: int, area: Area2D, area_shape: int, self_shape: int): | |
var trans = Physics2DServer.area_get_shape_transform(area.get_rid(), area_shape) | |
var tilemap = area.get_node("Items") as TileMap | |
var offset = 2 * tilemap.cell_size if tilemap.centered_textures else Vector2.ZERO | |
var orig = trans.xform(offset) | |
var pos = tilemap.world_to_map(orig) | |
if tilemap.get_cellv(pos) > -1: | |
tilemap.set_cellv(pos, -1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment