Unity and Cocos stay as parallel schemes; apps/minigame ships the Godot 4.7 WeChat pack for DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
1.9 KiB
GDScript
68 lines
1.9 KiB
GDScript
extends Node3D
|
|
|
|
@export var display_name := ""
|
|
@export var lines: PackedStringArray = PackedStringArray()
|
|
|
|
var _origin: Vector3
|
|
var _phase: float
|
|
var _radius: float
|
|
var _spin: float
|
|
var _bob: Node
|
|
var _bubble: Label3D
|
|
var _met := false
|
|
var _greet_cd := 0.0
|
|
|
|
func _ready() -> void:
|
|
add_to_group("npc")
|
|
_origin = global_position
|
|
_phase = randf() * TAU
|
|
_radius = 1.4 + randf() * 2.6
|
|
_spin = 0.28 + randf() * 0.22
|
|
if get_child_count() > 0:
|
|
_bob = get_child(0)
|
|
if _bob and _bob.has_method("set_moving"):
|
|
_bob.set_moving(true)
|
|
_bubble = Label3D.new()
|
|
_bubble.font_size = 36
|
|
_bubble.pixel_size = 0.011
|
|
_bubble.position = Vector3(0, 2.95, 0)
|
|
_bubble.modulate = Color(1, 1, 1, 0)
|
|
_bubble.outline_size = 8
|
|
_bubble.outline_modulate = Color(0.05, 0.05, 0.08, 0.85)
|
|
_bubble.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
|
add_child(_bubble)
|
|
|
|
func _process(delta: float) -> void:
|
|
_phase += delta * _spin
|
|
_greet_cd = maxf(0.0, _greet_cd - delta)
|
|
var offset := Vector3(cos(_phase) * _radius, 0.0, sin(_phase * 0.92) * _radius * 0.75)
|
|
var next := _origin + offset
|
|
var delta_pos := next - global_position
|
|
global_position = next
|
|
if delta_pos.length_squared() > 0.0001:
|
|
var yaw := atan2(delta_pos.x, delta_pos.z)
|
|
rotation.y = lerp_angle(rotation.y, yaw, 1.0 - exp(-8.0 * delta))
|
|
|
|
var player := get_tree().get_first_node_in_group("player") as Node3D
|
|
if player == null:
|
|
return
|
|
var dist := global_position.distance_to(player.global_position)
|
|
if dist < 3.2 and _greet_cd <= 0.0:
|
|
_greet()
|
|
_greet_cd = 6.0
|
|
elif dist > 5.5 and _bubble.modulate.a > 0.01:
|
|
_fade_bubble(0.0)
|
|
|
|
func _greet() -> void:
|
|
if lines.is_empty():
|
|
return
|
|
_bubble.text = lines[randi() % lines.size()]
|
|
_fade_bubble(1.0)
|
|
if not _met:
|
|
_met = true
|
|
get_tree().call_group("game", "on_npc_met", display_name)
|
|
|
|
func _fade_bubble(a: float) -> void:
|
|
var tw := create_tween()
|
|
tw.tween_property(_bubble, "modulate:a", a, 0.25)
|