Hey, im trying to make a boomerang projectile that comes back to the player after 1 second or after the projectile collides with something. Ive managed to make the player shoot the boomerang, and i've made the boomerang spin, but i cant figure out how to make it come back to the player and dissapear. Heres my code:
Player code:
if Input.is_action_just_pressed("action") and $Timer.is_stopped(): shoot()
func shoot():
var inst: Projectile = projectile.instantiate()
owner.add_child(inst)
inst.transform = $SpawnP.global_transform
$Timer.start()
Boomerang code:
extends Node2D
class_name Projectile
var speed: float = 5.0
var target = null
u/onready var player = get_node("res://UnScene/player.tscn")
func _ready():
$Timer.start()
func _physics_process(delta):
position += transform.x * speed
$Sprite2D.rotation += 0.3
if $Timer.is_stopped():
pass
#position.move_toward(player.position, delta*speed)