Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 48 additions & 31 deletions Assets/Scenes/Terrain.unity

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions Assets/Scripts/DebugCamera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DebugCamera : MonoBehaviour
{
public float speed = 5;
public float acceleration = 0.5f;
Vector3 momentum = Vector3.zero;
float turbo = 1f;

public float angularSpeed = 45f;
public float angularAcceleration = 0.5f;
Vector2 angularMomentum = Vector2.zero;

bool controlsActive = false;

float fps = 0;

void Start()
{
// Lock the cursor to the center of the screen
Cursor.lockState = CursorLockMode.Locked;

// Set controls to active
controlsActive = true;
}

void Update()
{
if (controlsActive)
{
/* MOVEMENT */

// Get user input
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");

float d = 0;
if(Input.GetKey(KeyCode.Space)){
d = 1;
}
else if(Input.GetKey(KeyCode.LeftControl)){
d = -1;
}

// Convert user input to a normalized 3D vector
Vector3 trajectory = new Vector3(h, d, v).normalized;

// Check for 'turbo' button and gradually increase or decrease turbo modifier accordingly
if (Input.GetKey(KeyCode.LeftShift))
{
turbo = Mathf.MoveTowards(turbo, 2f, Time.deltaTime * turbo);
}
else
{
turbo = Mathf.MoveTowards(turbo, 1f, Time.deltaTime * turbo);
}

// Set momentum by lerping to trajectory multiplied by desired speed and turbo
momentum = Vector3.Lerp(momentum, trajectory * speed * turbo, Time.deltaTime * acceleration * 10f);

// Move the camera
transform.Translate(momentum * Time.deltaTime);

/* LOOK */

// Get user input
float pitch = -Input.GetAxis("Mouse Y");
float yaw = Input.GetAxis("Mouse X");

// Reverse yaw when upside down for more intuitive input
if (Mathf.Abs(transform.eulerAngles.z - 180) <= 1f)
{
yaw *= -1f;
}

// Convert user input to a 2D vector
Vector2 rotation = new Vector2(yaw, pitch);

// Set angularMomentum by lerping to rotation
angularMomentum = Vector2.Lerp(angularMomentum, rotation, Time.deltaTime * angularAcceleration * 10f);

// Rotate the camera
transform.Rotate((Vector3.up * angularMomentum.x + transform.right * angularMomentum.y) * angularSpeed * Time.deltaTime, Space.World);
}

/* UTIL */

// Toggle cursor lock and control activation with tab
if (Input.GetKeyDown(KeyCode.Tab))
{
if (Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
controlsActive = false;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
controlsActive = true;
}
}

// Calculate frames per second
fps = Mathf.Round((fps + Mathf.Round(1f / Time.deltaTime)) * 0.5f);
}

void OnGUI(){
// Render FPS to GUI
GUIStyle style = new GUIStyle();
style.clipping = TextClipping.Overflow;
GUI.Label(new Rect(32,32,100,10), fps + "fps", style);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/DebugCamera.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Logs/Packages-Update.log
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ The following packages were added:
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0

=== Thu May 9 01:57:39 2019

Packages were changed.
Update Mode: updateDependencies

The following packages were updated:
com.unity.package-manager-ui from version 2.0.3 to 2.0.7
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"com.unity.ads": "2.0.8",
"com.unity.analytics": "3.2.2",
"com.unity.collab-proxy": "1.2.15",
"com.unity.package-manager-ui": "2.0.3",
"com.unity.package-manager-ui": "2.0.7",
"com.unity.purchasing": "2.0.3",
"com.unity.textmeshpro": "1.3.0",
"com.unity.modules.ai": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2018.3.2f1
m_EditorVersion: 2018.3.14f1