UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

32 lines (27 loc) 1.1 kB
import { Vector3 } from "three"; import { Behaviour, GameObject } from "../Component.js"; import { Voip } from "../Voip.js"; import { AvatarMarker } from "../webxr/WebXRAvatar.js"; /** @internal */ export class Avatar_MustacheShake extends Behaviour { private voip: Voip | null = null; private marker: AvatarMarker | null = null; private _startPosition : Vector3 | null = null; awake() { this.voip = GameObject.findObjectOfType(Voip, this.context); this.marker = GameObject.getComponentInParent(this.gameObject, AvatarMarker); // console.log(this); } update() { if (!this.voip || !this.marker) return; if(this.context.time.frameCount % 10 !== 0) return; const id = this.marker.connectionId; const freq = this.voip.getFrequency(id); if(freq == null) return; if(!this._startPosition) { this._startPosition = this.gameObject.position.clone(); } const t = freq / 100; this.gameObject.position.y = this._startPosition.y + t * 0.07; } }