Created
August 27, 2019 08:37
-
-
Save IRobS/4f2a41c4b0cfe2fdb105f60ba28d5b2c to your computer and use it in GitHub Desktop.
A simple 3rd person chase camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple 3rd person chase camera | |
*/ | |
background: #3b8; | |
min-height: 100%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre> | |
<code> | |
using UnityEngine; | |
using System.Collections; | |
public class SmoothFollow2 : MonoBehaviour | |
{ | |
public Transform target; | |
public float distance = 3.0f; | |
public float height = 3.0f; | |
public float damping = 5.0f; | |
public bool smoothRotation = true; | |
public bool followBehind = true; | |
public float rotationDamping = 10.0f; | |
void Update() | |
{ | |
Vector3 wantedPosition; | |
if (followBehind) | |
wantedPosition = target.TransformPoint(0, height, -distance); | |
else | |
wantedPosition = target.TransformPoint(0, height, distance); | |
transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping); | |
if (smoothRotation) | |
{ | |
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up); | |
transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping); | |
} | |
else transform.LookAt(target, target.up); | |
} | |
} | |
</code> | |
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// alert('Hello world!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment