Now About Social Code
summaryrefslogtreecommitdiff
path: root/addons/fpc/reticles/reticle_1.tscn
blob: bb83b839bcf7dc966d6d5b411bb7f72767443b0e (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
[gd_scene load_steps=2 format=3 uid="uid://3mij3cjhkwsm"]

[sub_resource type="GDScript" id="GDScript_a8kpl"]
script/source = "extends CenterContainer


@export_category(\"Reticle\")
@export_group(\"Nodes\")
@export var reticle_lines : Array[Line2D]
@export var character : CharacterBody3D

@export_group(\"Animate\")
@export var animated_reticle : bool = true
@export var reticle_speed : float = 0.5
@export var reticle_spread : float = 4.0

@export_group(\"Dot Settings\")
@export var dot_size : int = 1
@export var dot_color : Color = Color.WHITE

@export_group(\"Line Settings\")
@export var line_color : Color = Color.WHITE
@export var line_width : int = 2
@export var line_length : int = 10
@export var line_distance : int = 5
@export_enum(\"None\", \"Round\") var cap_mode : int = 0


func _process(_delta):
	if visible: # If the reticle is disabled (not visible), don't bother updating it
		update_reticle_settings()
		if animated_reticle:
			animate_reticle_lines()


func animate_reticle_lines():
	var vel = character.get_real_velocity()
	var origin = Vector3(0,0,0)
	var pos = Vector2(0,0)
	var speed = origin.distance_to(vel)
	
	reticle_lines[0].position = lerp(reticle_lines[0].position, pos + Vector2(0, -speed * reticle_spread), reticle_speed)
	reticle_lines[1].position = lerp(reticle_lines[1].position, pos + Vector2(-speed * reticle_spread, 0), reticle_speed)
	reticle_lines[2].position = lerp(reticle_lines[2].position, pos + Vector2(speed * reticle_spread, 0), reticle_speed)
	reticle_lines[3].position = lerp(reticle_lines[3].position, pos + Vector2(0, speed * reticle_spread), reticle_speed)


func update_reticle_settings():
	# Dot
	$dot.scale.x = dot_size
	$dot.scale.y = dot_size
	$dot.color = dot_color
	
	# Lines
	for line in reticle_lines:
		line.default_color = line_color
		line.width = line_width
		if cap_mode == 0:
			line.begin_cap_mode = Line2D.LINE_CAP_NONE
			line.end_cap_mode = Line2D.LINE_CAP_NONE
		elif cap_mode == 1:
			line.begin_cap_mode = Line2D.LINE_CAP_ROUND
			line.end_cap_mode = Line2D.LINE_CAP_ROUND
	
	# Please someone find a better way to do this
	reticle_lines[0].points[0].y = -line_distance
	reticle_lines[0].points[1].y = -line_length - line_distance
	reticle_lines[1].points[0].x = -line_distance
	reticle_lines[1].points[1].x = -line_length - line_distance
	reticle_lines[2].points[0].x = line_distance
	reticle_lines[2].points[1].x = line_length + line_distance
	reticle_lines[3].points[0].y = line_distance
	reticle_lines[3].points[1].y = line_length + line_distance
"

[node name="Reticle" type="CenterContainer" node_paths=PackedStringArray("reticle_lines")]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
script = SubResource("GDScript_a8kpl")
reticle_lines = [NodePath("top"), NodePath("left"), NodePath("right"), NodePath("bottom")]

[node name="dot" type="Polygon2D" parent="."]
polygon = PackedVector2Array(-1, -1, 1, -1, 1, 1, -1, 1)

[node name="top" type="Line2D" parent="."]
points = PackedVector2Array(0, -5, 0, -15)
width = 2.0

[node name="left" type="Line2D" parent="."]
points = PackedVector2Array(-5, 0, -15, 0)
width = 2.0

[node name="right" type="Line2D" parent="."]
points = PackedVector2Array(5, 0, 15, 0)
width = 2.0

[node name="bottom" type="Line2D" parent="."]
points = PackedVector2Array(0, 5, 0, 15)
width = 2.0