import { _decorator, Component, Node, Vec3 } from 'cc' const { ccclass, property } = _decorator /** * Lightweight NPC / dust motion — keeps scene alive without AI stack. */ @ccclass('NpcWander') export class NpcWander extends Component { @property(Node) lookAt: Node | null = null @property mode: 'wander' | 'dust' = 'wander' @property radius = 1.8 @property speed = 0.55 private _origin = new Vec3() private _t = Math.random() * 10 private _baseY = 0 start() { this._origin.set(this.node.position) this._baseY = this.node.position.y this._t = Math.random() * 10 } update(dt: number) { this._t += dt if (this.mode === 'dust') { const p = this.node.position const y = this._baseY + Math.abs(Math.sin(this._t * this.speed)) * 1.2 const x = p.x + Math.sin(this._t * 0.25 + p.z) * dt * 0.15 this.node.setPosition(x, y, p.z) return } const ox = this._origin.x + Math.cos(this._t * this.speed) * this.radius const oz = this._origin.z + Math.sin(this._t * this.speed * 0.85) * this.radius this.node.setPosition(ox, this._origin.y, oz) if (this.lookAt) { const t = this.lookAt.worldPosition const dx = t.x - ox const dz = t.z - oz if (dx * dx + dz * dz > 0.01) { const yaw = (Math.atan2(dx, dz) * 180) / Math.PI this.node.setRotationFromEuler(0, yaw, 0) } } } }