Created
August 28, 2019 14:48
-
-
Save IRobS/97b1393c8ff6539cf3498bdd9b1b2f82 to your computer and use it in GitHub Desktop.
rotating tracking 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
/** | |
* rotating tracking camera | |
*/ | |
background: #fc1; | |
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 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> |
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