forked from cgvr/DeltaVR
npcs turn smoothly towards player
This commit is contained in:
@@ -11,9 +11,7 @@
|
|||||||
* robert on plekiline, vunts õiget värvi :)
|
* robert on plekiline, vunts õiget värvi :)
|
||||||
* quest marker järjest järgmise tegevuse kohal: mikrofon, siis nupud
|
* quest marker järjest järgmise tegevuse kohal: mikrofon, siis nupud
|
||||||
* character billboard:
|
* character billboard:
|
||||||
* tulnukale korraliku resolutsiooniga suu / silm liikuma
|
|
||||||
* klaas on näha temast eespool
|
* klaas on näha temast eespool
|
||||||
* pööramine kaamera poole - sujuvalt (slerp)
|
|
||||||
|
|
||||||
Can't/Won't Do:
|
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**
|
* glTF loading: vahetada ära shader Universal render pipelin Lit, mitte panna buildi kaasa glTf oma - **ei saa, objekt on siis ilma tekstuurita, lihtsalt hall**
|
||||||
|
|||||||
@@ -5,17 +5,15 @@ using UnityEngine;
|
|||||||
|
|
||||||
public abstract class NPCController : MonoBehaviour
|
public abstract class NPCController : MonoBehaviour
|
||||||
{
|
{
|
||||||
protected Transform playerTransform;
|
[Header("Movement Config")]
|
||||||
|
public Transform mouth;
|
||||||
|
public float turnSpeed = 5f;
|
||||||
|
|
||||||
[Header("Voiceline Amplitude Timeline Config")]
|
[Header("Voiceline Amplitude Timeline Config")]
|
||||||
public string voicelinesFolder = "CharacterVoicelines";
|
public string voicelinesFolder = "CharacterVoicelines";
|
||||||
public string characterSpecificFolder;
|
public string characterSpecificFolder;
|
||||||
public string[] voiceLineKeys;
|
public string[] voiceLineKeys;
|
||||||
|
|
||||||
|
|
||||||
[Header("Mouth Transform")]
|
|
||||||
public Transform mouth; // assign your billboard mouth object
|
|
||||||
|
|
||||||
[Header("Mouth Animation Settings")]
|
[Header("Mouth Animation Settings")]
|
||||||
public float minScaleY = 0.3f;
|
public float minScaleY = 0.3f;
|
||||||
public float maxScaleY = 1.0f;
|
public float maxScaleY = 1.0f;
|
||||||
@@ -24,6 +22,8 @@ public abstract class NPCController : MonoBehaviour
|
|||||||
public float release = 0.2f; // slower closing
|
public float release = 0.2f; // slower closing
|
||||||
public bool inverted = false;
|
public bool inverted = false;
|
||||||
|
|
||||||
|
protected Transform playerTransform;
|
||||||
|
|
||||||
private float[] rmsCurve;
|
private float[] rmsCurve;
|
||||||
private EventInstance currentVoicelineEvent;
|
private EventInstance currentVoicelineEvent;
|
||||||
private bool isSpeaking;
|
private bool isSpeaking;
|
||||||
@@ -50,9 +50,19 @@ public abstract class NPCController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (playerTransform != null)
|
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);
|
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())
|
if (isSpeaking && rmsCurve != null && currentVoicelineEvent.isValid())
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user