31 lines
743 B
GDScript
31 lines
743 B
GDScript
extends Node2D
|
|
|
|
var a = Vector2(100,0)
|
|
var b = Vector2(0,100)
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
pass
|
|
|
|
func _draw():
|
|
print("draw: ", a, b)
|
|
draw_line(a, b, Color.GOLD, 20, true)
|
|
|
|
func align(a_new, b_new):
|
|
var difference = b_new - a_new
|
|
var halfway = a_new + (difference / 2)
|
|
var distance = difference.length()
|
|
var rotation_new = difference.angle()
|
|
position = halfway
|
|
a = halfway - a_new
|
|
b = halfway - b_new
|
|
$StaticBody2D/CollisionShape2D.shape.set_size(Vector2(distance, 20))
|
|
$StaticBody2D/CollisionShape2D.rotation = rotation_new
|
|
queue_redraw()
|
|
|
|
|