Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MemokingMH |
Question is simple. Can u add collisions to a line thet’s drwan by draw_line function
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MemokingMH |
Question is simple. Can u add collisions to a line thet’s drwan by draw_line function
Reply From: | exuin |
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.
Reply From: | scrubswithnosleeves |
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