godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.34k stars 21.06k forks source link

Raycast2D.add_exception() not working with TileMap node #22891

Closed wingedadventurer closed 3 years ago

wingedadventurer commented 6 years ago

Godot version: Latest stable (3.0.6) 2018-10-09 daily build

Issue description: Like the title says, it seems that Raycast2D (and probably Raycast 3D) doesn't add a properly setup TileMap with collisions to its exceptions when using add_exception() to the detected TileMap.

I made a TileMap consisting of walls with collisions. Tileset was set up correctly as intented. I spread a RayCast across some placed tiles, and I made a code where if the ray detects any node, it adds it as an exception. The code works perfectly for any type of collision object, except for TileSet which is never added to its exceptions.

Check the minimal reproduction project for more info.

Minimal reproduction project: Raycast TileMap bug.zip (made with Godot stable 3.0.6)

Edit: Turn on visible collision shapes to actually see your raycast.

groud commented 6 years ago

Can you try with 3.1 alpha ?

wingedadventurer commented 6 years ago

@groud I've just tried with 3.1 alpha, and add_exception() still fails with TileMap.

Razzlegames commented 5 years ago

This is too bad, since I was doing things like this, but now I get an infinite loop if TileMaps with collision are present :( :

I can prob get away with just grabbing the first colliding body and not looping for now.


func _physics_process(delta):

    var collision_obj_to_add_back = []
    while is_colliding():
        var col = get_collider()

        if  col is PhysicsBody2D :
            col.propagate_call("setOneWayCollision", [disable_collisions, physics_object], true)
        if !(col is Area2D):
            collision_obj_to_add_back.append(col)
        add_exception(col)
        force_raycast_update()

    for col in collision_obj_to_add_back:
        remove_exception(col)
akien-mga commented 4 years ago

Related to #24739 and #27282. The TileMap and GridMap collision logic needs to be reworked to properly solve these issues.

KoBeWi commented 3 years ago

Still valid in 3.2.4 beta3

This is weird though. The add_exception() has this condition: https://github.com/godotengine/godot/blob/2ac8c3b6dc211ed7cf62b9971a3c8eaadad7a3b2/scene/2d/ray_cast_2d.cpp#L239-L242 It's expected that TileMaps are omitted, buuut there's also add_exception_rid(), which doesn't have this check. However add_exception_rid(RID(collider)) doesn't work either, while theoretically it should 🤔

groud commented 3 years ago

Related to/duplicate of: https://github.com/godotengine/godot/issues/17090

KoBeWi commented 3 years ago

Closing as duplicate of #17090