-
Notifications
You must be signed in to change notification settings - Fork 4
/
straight2D.gd
49 lines (36 loc) · 1.21 KB
/
straight2D.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
tool
extends Node2D
# class member variables go here, for example:
var first = Vector2(0,0)
var length = 50 * 15 # 30 px = 2 m so 15 px = 1 m
var last = Vector2(0,0)
#var pos_start = Vector2(0,0)
#var pos_end = Vector2(0,0)
var start_vector = Vector2(0,0)
var end_vector = Vector2(0,0)
var start_ref = Vector2(0,0)
var end_ref = Vector2(0,0)
var thick = 4
func _ready():
last = Vector2(first.x+length, first.y)
var pos_start = Vector2(first.x+length/4, first.y)
var pos_end = Vector2(last.x-length/4, last.y)
# normalizing the vectors solves problems with angle_to()
start_vector = (pos_start - first).normalized()*10
#B-A = from a to b
end_vector = (last - pos_end).normalized()*10
#print("[Straight] Start vector: " + str(start_vector) + " end vector " + str(end_vector))
start_ref = first+start_vector
end_ref = last+end_vector
# Called every time the node is added to the scene.
# Initialization here
#pass
func _get_item_rect():
return Rect2(Vector2(-1,-1), Vector2(length, 5))
func _draw():
draw_line(first, last, Color(0,0,0), thick)
draw_line(first, start_ref, Color(0,1,0))
draw_line(last, end_ref, Color(1,0,0))
# debugging
draw_circle(first, 1, Color(0,1,0))
draw_circle(last, 1, Color(1,0,0))