xiandie/scene/ground/script/c02/裂缝红色眼睛.gd

38 lines
887 B
GDScript

@tool
extends Node2D
@export var watching_node: Node2D
@export var center_eye := false
@export var eye_texture: Texture2D:
set(val):
eye_texture = val
if is_node_ready():
eye_sprite.texture = eye_texture
@export var radius := 30.0:
set(val):
radius = val
if is_node_ready():
_setup_eye_direction()
@onready var eye_sprite := $ as Sprite2D
func _ready() -> void:
eye_sprite.texture = eye_texture
_setup_eye_direction()
func _physics_process(_delta: float) -> void:
if not watching_node or Engine.is_editor_hint():
return
_setup_eye_direction()
func _setup_eye_direction():
if not watching_node:
eye_sprite.position.y = radius
return
# set eye_sprite position at the arrow head from self's position to watching_node's position
var direction = watching_node.global_position - global_position
eye_sprite.position = direction.normalized() * radius