-
-
Save KABBOUCHI/987d146f9fb7fe88dc53d79df586b3f1 to your computer and use it in GitHub Desktop.
Revisions
-
IRCSS renamed this gist
Jan 15, 2020 . 1 changed file with 14 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,24 +5,24 @@ // Moves Camera similar to how camera is moved in the Unity view port. Drop the scrip on the game object which has the camera and you wish to move. public class SmoothGameCameraMovement : MonoBehaviour { public float lateralSpeed = 0.0015f; public float LongitudinalSpeed = 0.0008f; public float verticalSpeed = 0.001f; public float mouseMoevementSpeed = 0.2f; public float ShiftMultiplyer = 4f; public bool InvertedY = false; // ------------------------------------------------------ // these need to be > 0 and <= 1. closer to 0 is smoother movement public float verticalFilter = 0.003f; public float lateralFilter = 0.005f; public float LongitudinalFilter = 0.005f; public float mouseFilter = 0.04f; // ------------------------------------------------------ @@ -48,12 +48,12 @@ void Update() { // ------------------------------------------------------------------------------------------------------- // ======================================== // Speed Multiplyer speedMultiplyer = Mathf.Lerp(speedMultiplyer, 1f, 0.1f); if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.Mouse1)) { speedMultiplyer += 0.2f; speedMultiplyer = Mathf.Clamp(speedMultiplyer, 1f, ShiftMultiplyer); @@ -68,7 +68,8 @@ void Update() lateral = Mathf.Clamp(lateral, -1f, 1f); float x = Input.GetAxis("Horizontal"); if (Input.GetKey(KeyCode.Mouse1)) lateral += x * lateralSpeed; this.transform.position += this.transform.right * lateral * speedMultiplyer; @@ -80,16 +81,16 @@ void Update() float y = Input.GetAxis("Vertical"); if (Input.GetKey(KeyCode.Mouse1)) longitudinal += y * LongitudinalSpeed; this.transform.position += this.transform.forward * longitudinal* speedMultiplyer; // ======================================== // Up Down Movement vertical = Mathf.Lerp(vertical, 0f, verticalFilter); if (Input.GetKey(KeyCode.E) && Input.GetKey(KeyCode.Mouse1)) vertical += verticalSpeed; // UP if (Input.GetKey(KeyCode.Q) && Input.GetKey(KeyCode.Mouse1)) vertical -= verticalSpeed; // DOWN this.transform.position += this.transform.up * vertical * speedMultiplyer; @@ -98,14 +99,14 @@ void Update() // Mouse Movement X float mouseX = Input.GetAxis("Mouse X"); if (Input.GetKey(KeyCode.Mouse1)) TransformDummy.transform.Rotate(Vector3.up * mouseX* mouseMoevementSpeed, Space.World); // ======================================== // Mouse Movement Y float mouseY = Input.GetAxis("Mouse Y"); if (Input.GetKey(KeyCode.Mouse1)) TransformDummy.transform.Rotate(TransformDummy.transform.right * -1f * mouseY* mouseMoevementSpeed, Space.World); this.transform.rotation = Quaternion.Slerp(this.transform.rotation, TransformDummy.transform.rotation, mouseFilter); -
IRCSS created this gist
Jan 15, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,115 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; // Moves Camera similar to how camera is moved in the Unity view port. Drop the scrip on the game object which has the camera and you wish to move. public class MoveCameraNonVR : MonoBehaviour { public float lateralSpeed = 0.0015f; public float LongitudinalSpeed = 0.0008f; public float verticalSpeed = 0.0015f; public float mouseMoevementSpeed = 0.8f; public float ShiftMultiplyer = 4f; public bool InvertedY = false; // ------------------------------------------------------ // these need to be > 0 and <= 1. closer to 0 is smoother movement public float verticalFilter = 0.005f; public float lateralFilter = 0.005f; public float LongitudinalFilter = 0.005f; public float mouseFilter = 0.1f; // ------------------------------------------------------ private float vertical; private float lateral; private float longitudinal; private float speedMultiplyer = 1f; private float inversion = -1f; private GameObject TransformDummy; void Start() { if (InvertedY) inversion = 1f; else inversion = -1f; if (TransformDummy == null) TransformDummy = new GameObject("TransformDummy"); TransformDummy.transform.rotation= this.transform.rotation; } void Update() { // ------------------------------------------------------------------------------------------------------- if (!Input.GetKey(KeyCode.Mouse1)) return; // ======================================== // Speed Multiplyer speedMultiplyer = Mathf.Lerp(speedMultiplyer, 1f, 0.1f); if (Input.GetKey(KeyCode.LeftShift)) { speedMultiplyer += 0.2f; speedMultiplyer = Mathf.Clamp(speedMultiplyer, 1f, ShiftMultiplyer); } // ======================================== // Left Right Movement lateral = Mathf.Lerp(lateral, 0f, lateralFilter); lateral = Mathf.Clamp(lateral, -1f, 1f); float x = Input.GetAxis("Horizontal"); lateral += x * lateralSpeed; this.transform.position += this.transform.right * lateral * speedMultiplyer; // ======================================== // Foward Backward Movement longitudinal = Mathf.Lerp(longitudinal, 0f, LongitudinalFilter); longitudinal = Mathf.Clamp(longitudinal, -1f, 1f); float y = Input.GetAxis("Vertical"); longitudinal += y * LongitudinalSpeed; this.transform.position += this.transform.forward * longitudinal* speedMultiplyer; // ======================================== // Up Down Movement vertical = Mathf.Lerp(vertical, 0f, verticalFilter); if (Input.GetKey(KeyCode.E)) vertical += verticalSpeed; // UP if (Input.GetKey(KeyCode.Q)) vertical -= verticalSpeed; // DOWN this.transform.position += this.transform.up * vertical * speedMultiplyer; // ======================================== // Mouse Movement X float mouseX = Input.GetAxis("Mouse X"); TransformDummy.transform.Rotate(Vector3.up * mouseX* mouseMoevementSpeed, Space.World); // ======================================== // Mouse Movement Y float mouseY = Input.GetAxis("Mouse Y"); TransformDummy.transform.Rotate(TransformDummy.transform.right * -1f * mouseY* mouseMoevementSpeed, Space.World); this.transform.rotation = Quaternion.Slerp(this.transform.rotation, TransformDummy.transform.rotation, mouseFilter); } }