blob: cedb028ace7d2148dedc374580557efbfef824c5 (
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
|
extends Node
var player : Entity = null
@export var weapon : Node2D
@export var pivot : Node2D
@export var sprite : Node2D
var delta_pos : Vector2
var can_attack : bool = true
func _on_detect_area_body_entered(body:Node2D) -> void:
print(body)
if body is Entity:
if body.is_player:
player = body
var parent : Entity
func _process(_delta: float) -> void:
parent = get_node("..")
if !player:
return
delta_pos = player.global_position - parent.global_position
var angle = rad_to_deg(atan2(delta_pos.y, delta_pos.x)) - 90
pivot.rotation_degrees = angle
if delta_pos.x < 0:
if pivot.position.x > 0: pivot.position.x *= -1
if pivot.scale.x > 0: pivot.scale.x *= -1
if sprite.scale.x > 0: sprite.scale.x *= -1
else:
if pivot.position.x < 0: pivot.position.x *= -1
if pivot.scale.x < 0: pivot.scale.x *= -1
if sprite.scale.x < 0: sprite.scale.x *= -1
if can_attack:
weapon.action()
$"AttackCooldown".start()
can_attack = false
func _on_attack_cooldown_timeout() -> void:
can_attack = true
|