0 votes

Question is simple. Can u add collisions to a line thet's drwan by draw_line function

Godot version 3.2
in Engine by (47 points)

2 Answers

0 votes

Yes, but you will have to make your own collision shape and place it where the line is. Lines do not just have collision on their own.

by (7,042 points)
0 votes

Yes here is a code snippet that I use to basically do that, excepts with a raycast and line2D node, but the principle is the same.

if raycast.is_colliding():
        var coll_point = raycast.get_collision_point()
        laser.points[1] = to_local(coll_point)
        particles.global_position = coll_point

        var shape = RectangleShape2D.new()
        var half_way_amount = (global_position - coll_point)/2.0
        var center_point = global_position - half_way_amount
        shape.extents.x = half_way_amount.rotated(rotation).x

        $CollisionShape2D.shape = shape
by (576 points)
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.