This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/SpaceNavigator/Runtime samples/- Fly around/Scripts/FlyAround.cs
2020-07-09 11:41:01 -07:00

21 lines
662 B
C#

using UnityEngine;
using SpaceNavigatorDriver;
public class FlyAround : MonoBehaviour {
public bool HorizonLock = true;
public void Update () {
transform.Translate(SpaceNavigator.Translation, Space.Self);
if (HorizonLock) {
// This method keeps the horizon horizontal at all times.
// Perform azimuth in world coordinates.
transform.Rotate(Vector3.up, SpaceNavigator.Rotation.Yaw() * Mathf.Rad2Deg, Space.World);
// Perform pitch in local coordinates.
transform.Rotate(Vector3.right, SpaceNavigator.Rotation.Pitch() * Mathf.Rad2Deg, Space.Self);
}
else {
transform.Rotate(SpaceNavigator.Rotation.eulerAngles, Space.Self);
}
}
}