Hsif/Scripts/Spear.gd

44 lines
786 B
GDScript

extends Area2D
var fish = CharacterBody2D
@export
var target = 0
@export
var ai = 0
@export
var speed = 1
# Called when the node enters the scene tree for the first time.
func _ready():
fish = get_tree().get_first_node_in_group("Fish") #fish
match ai:
#set position
0:
position = Vector2(target, -1087)
#fish position
1:
position = Vector2(fish.position.x,-1087)
#predict position
2: pass
if position.x > 907:
position.x = 907
if position.x < -907:
position.x = -907
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
goFish()
func goFish():
position.y = position.y + speed
if position.y > 1222:
queue_free()
func _on_body_entered(body):
if body.is_in_group("Fish"):
fish.hurt = true