1
0
forked from cgvr/DeltaVR

npcs turn smoothly towards player

This commit is contained in:
2026-02-07 12:54:27 +02:00
parent 2ecda2b9a0
commit 32d0686cd2
3 changed files with 19 additions and 11 deletions

View File

@@ -11,9 +11,7 @@
* robert on plekiline, vunts õiget värvi :)
* quest marker järjest järgmise tegevuse kohal: mikrofon, siis nupud
* character billboard:
* tulnukale korraliku resolutsiooniga suu / silm liikuma
* klaas on näha temast eespool
* pööramine kaamera poole - sujuvalt (slerp)
Can't/Won't Do:
* glTF loading: vahetada ära shader Universal render pipelin Lit, mitte panna buildi kaasa glTf oma - **ei saa, objekt on siis ilma tekstuurita, lihtsalt hall**

View File

@@ -5,17 +5,15 @@ using UnityEngine;
public abstract class NPCController : MonoBehaviour
{
protected Transform playerTransform;
[Header("Movement Config")]
public Transform mouth;
public float turnSpeed = 5f;
[Header("Voiceline Amplitude Timeline Config")]
public string voicelinesFolder = "CharacterVoicelines";
public string characterSpecificFolder;
public string[] voiceLineKeys;
[Header("Mouth Transform")]
public Transform mouth; // assign your billboard mouth object
[Header("Mouth Animation Settings")]
public float minScaleY = 0.3f;
public float maxScaleY = 1.0f;
@@ -24,6 +22,8 @@ public abstract class NPCController : MonoBehaviour
public float release = 0.2f; // slower closing
public bool inverted = false;
protected Transform playerTransform;
private float[] rmsCurve;
private EventInstance currentVoicelineEvent;
private bool isSpeaking;
@@ -50,9 +50,19 @@ public abstract class NPCController : MonoBehaviour
{
if (playerTransform != null)
{
// As if player is on same Y coordinate as this object, to not rotate around Y axis.
// Keep target on same Y as this object (no pitch/roll), so we only yaw.
Vector3 lookTargetPos = new Vector3(playerTransform.position.x, transform.position.y, playerTransform.position.z);
transform.LookAt(lookTargetPos);
// Direction from this object to the target (on horizontal plane)
Vector3 toTarget = (lookTargetPos - transform.position);
if (toTarget.sqrMagnitude > 0.0001f) // avoid zero-length
{
Quaternion targetRot = Quaternion.LookRotation(toTarget.normalized);
// Interpolate a little each frame towards the target rotation.
float t = Mathf.Clamp01(Time.deltaTime * turnSpeed);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, t);
}
}
if (isSpeaking && rmsCurve != null && currentVoicelineEvent.isValid())

Binary file not shown.