Search code examples
godotgdscript

Collision detection with Godot 4.0 3D


I am a newbe to programing in GDScript 2.0 and am new to GD in general. I need to set the player position to 0,0,0 when touching an object that is in the group called "lava".

I am using godot 4.0 and trying to make a 3d game.

Code:

func _body_entered(body):
    if is_in_group("lava"):
        character_body.translation = Vector3(1, 1, 1)
        # Set the position of the node to (x, y, z)`[enter image description here][1]

It is not giving me an error but it is not working.


Solution

  • just do this

    for index in range(get_slide_collision_count()):
        var collision = get_slide_collision(index)
        if collision.get_collider().is_in_group("Lava"):
            print("colided")