Skip to content

Instantly share code, notes, and snippets.

@IRobS
Created August 28, 2019 14:48
Show Gist options
  • Save IRobS/97b1393c8ff6539cf3498bdd9b1b2f82 to your computer and use it in GitHub Desktop.
Save IRobS/97b1393c8ff6539cf3498bdd9b1b2f82 to your computer and use it in GitHub Desktop.
rotating tracking camera
/**
* rotating tracking camera
*/
background: #fc1;
min-height: 100%;
<pre>
<code>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraTrack : MonoBehaviour
{
public GameObject player;
public Vector3 offset = new Vector3(5f, 5f, 0f);
// Start is called before the first frame update
void Start()
{
if (offset == null)
{
offset = transform.position - player.transform.position;
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
offset = Quaternion.Euler(0, 90, 0) * offset;
transform.position = player.transform.position + offset;
Quaternion rot = Quaternion.LookRotation(player.transform.position - transform.position);
transform.rotation = rot;
}
transform.position = player.transform.position + offset;
}
}</code>
</pre>
// alert('Hello world!');
{"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