0 votes

In my player script I emit a signal when the mouse is pressed and a collision is detected with a RayCast2d collision point. This should remove the block that the RayCast2d being projected from the player collides with, but it seems to be inconsistent about what blocks it actually removes even some parts of the map it wont remove any blocks at all.
I didn't notice anything amiss when I output all the relevant variables to the console. I've been hitting my head on a wall trying to diagnose this for hours at this point any help is appreciated.

Here's the relevant code:

extends KinematicBody2D

signal hit(collision_point)

func mine():
    if mine_ray.is_colliding():
        var collision_point = mine_ray.get_collision_point()
        emit_signal("hit", collision_point)

func _physics_process(delta):

    if Input.is_action_pressed("ui_mine"):
        mine()

And in the script for the tilemap I have:

extends TileMap

func _on_Player_hit(collision_point):
    var tile = world_to_map(collision_point)
    set_cell(tile.x, tile.y, -1)

Thanks for your input!

asked Jul 19 in Engine by Cal_9000 (15 points)

1 Answer

0 votes

you can try visualizing the collision shape, there is an option under debug on the top bar

I just solved a similar issue, it is caused by the collision shapes of the tiles are colliding with each other and shift away

answered Jul 20 by Dipsy Wong (14 points)

Unfortunately thats not the issue here, I can see the ray intersecting with a tile and yet when I click it doesnt always remove the expected one.

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 How to use this Q&A? before posting your first questions.