File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed
Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 11version https://git-lfs.github.com/spec/v1
2- oid sha256:a0a43e3ef5debe8151d5424cc7a2f9daf97e5cec99557ddd808f1241adca16a6
3- size 19701
2+ oid sha256:026cc16090895fccf6986872589ab0129472754d2336647da1d6b17d0a5771e0
3+ size 19736
Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using UnityEngine ;
44
5+ /**
6+ * Make a game object face the camera regardless of its parent transform(s)
7+ */
58public class FaceCamera : MonoBehaviour {
69
7- // make a game object face the camera regardless of its parent transform
8-
9- Camera cam ;
10+ public bool slowly ; // whether or not to step or "transport"
11+ float zAxisStep = 0 ; // amount to step
12+ [ Range ( 0f , .5f ) ]
13+ public float stepScalar = .01f ; // how fast to step
14+ Camera cam ; // which camera to face
1015
1116 private void Awake ( )
1217 {
@@ -15,8 +20,14 @@ private void Awake ()
1520
1621 void Update ( )
1722 {
18- // turn on the Y axis to face camera
19- transform . rotation = Quaternion . Euler ( 0 , cam . transform . eulerAngles . y , 0 ) ;
23+ // should we slowly step
24+ if ( slowly )
25+ zAxisStep = Mathf . Lerp ( transform . rotation . eulerAngles . z , 0 , stepScalar ) ;
26+ else
27+ zAxisStep = 0 ;
28+
29+ // face the camera on each axis
30+ transform . rotation = Quaternion . Euler ( 0 , cam . transform . eulerAngles . y , zAxisStep ) ;
2031 }
2132
2233}
You can’t perform that action at this time.
0 commit comments