Hsif/Scripts/Hook.gd

51 lines
901 B
GDScript

extends Area2D
var fish = CharacterBody2D
var cast = false
@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, -660)
#fish position
1:
position = Vector2(fish.position.x,-660)
#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():
if cast == false:
position.y = position.y + speed
else:
position.y = position.y - speed
if position.y > 1222:
cast = true
if position.y < -660:
queue_free()
func _on_body_entered(body):
if body.is_in_group("Fish"):
fish.hurt = true