Skip to content

Commit

Permalink
Smaller optional features added to the Billboard component (lerping a…
Browse files Browse the repository at this point in the history
…nd only rotating around the y axis)
  • Loading branch information
cs-util committed Nov 25, 2023
1 parent 932fb1c commit be3bb77
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace com.csutil {

public class LookAtBillboard : MonoBehaviour {

public Transform targetToLookAt;
public float lerpSpeed = 0;
public float lerpOmega = 20;
private Vector3 _lerpVelocity = Vector3.zero;
public bool onlyRotateAroundY = false;

private void OnEnable() {
if (targetToLookAt == null) { targetToLookAt = Camera.main.transform; }
}

private void Update() {
transform.forward = targetToLookAt.forward;
var newForward = targetToLookAt.forward;
if (onlyRotateAroundY) {
newForward = Vector3.Scale(newForward, new Vector3(1, 0, 1)).normalized;
}
if (lerpSpeed > 0) {
transform.forward = transform.forward.LerpWithVelocity(newForward, ref _lerpVelocity, Time.deltaTime * lerpSpeed, lerpOmega);
} else {
transform.forward = newForward;
}
}

}
Expand Down

0 comments on commit be3bb77

Please sign in to comment.