-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTangleKelp.gd
More file actions
50 lines (34 loc) · 1.25 KB
/
TangleKelp.gd
File metadata and controls
50 lines (34 loc) · 1.25 KB
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
extends StaticBody2D
const GRAB_DIST: float = 650
const FOLLOW_DIST: float = 900
@onready var attack_collision: CollisionShape2D = $"ContinuousAttack/CollisionShape2D"
@onready var hurtbox: Hurtbox = $"Hurtbox"
@onready var ropes: Array[VerletRope] = [
$"Rope1/VerletRope",
$"Rope2/VerletRope",
$"Rope3/VerletRope",
$"Rope4/VerletRope",
]
var target_rope_position: Vector2
@onready var rope_position: Vector2 = global_position # Lerped value
func _ready() -> void:
for rope in ropes:
rope.end_pos_on = true
hurtbox.died.connect(die)
func _process(delta: float) -> void:
var diver_pos = Global.player.global_position
var dist: float = global_position.distance_to(diver_pos)
if dist < GRAB_DIST:
target_rope_position = diver_pos
elif dist < FOLLOW_DIST:
target_rope_position = (diver_pos - global_position).normalized() * GRAB_DIST + global_position
else:
target_rope_position = Vector2(0, -500) + global_position
rope_position = rope_position + (target_rope_position - rope_position) * 0.03
var is_on_screen: bool = $VisibleOnScreenNotifier2D.is_on_screen()
for rope in ropes:
rope.end_pos = rope_position
rope.is_on_screen = is_on_screen
attack_collision.global_position = rope_position
func die() -> void:
queue_free()