Skip to content

Commit e6cced7

Browse files
committed
Update FaceCamera to slowly step avatars to upright
1 parent 4c42730 commit e6cced7

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a0a43e3ef5debe8151d5424cc7a2f9daf97e5cec99557ddd808f1241adca16a6
3-
size 19701
2+
oid sha256:026cc16090895fccf6986872589ab0129472754d2336647da1d6b17d0a5771e0
3+
size 19736

Assets/_Project/Scripts/Effects/FaceCamera.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44

5+
/**
6+
* Make a game object face the camera regardless of its parent transform(s)
7+
*/
58
public 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
}

0 commit comments

Comments
 (0)