From 25059da21916532c2dc541f9ce54d1748f90292e Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Mon, 23 Apr 2018 15:12:49 +0200 Subject: [PATCH] Improved camera --- Assets/Scripts/CameraControl.cs | 20 ++++++++++++++++---- Assets/Scripts/PlayerMovement.cs | 1 - Assets/graphics/textures/car.meta | 8 ++++++++ Assets/graphics/textures/tmp.meta | 8 ++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Assets/graphics/textures/car.meta create mode 100644 Assets/graphics/textures/tmp.meta diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index a36dc31..396151c 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -5,10 +5,20 @@ using UnityEngine; public class CameraControl : MonoBehaviour { [SerializeField] - private GameObject followThis; + private float followSpeed = 0.05f; + [SerializeField] + private float minZoom = 5; + [SerializeField] + private float zoomFactor = 4; + [SerializeField] + private float zoomSpeed = 0.05f; + [SerializeField] + private int startingDist = 5; + [SerializeField] + private GameObject followThis; void Start() { - Camera.main.orthographicSize = 5; + Camera.main.orthographicSize = minZoom; if ( followThis == null ) return; } @@ -18,14 +28,16 @@ public class CameraControl : MonoBehaviour { return; var target = followThis.transform.position; var targetVec = target - transform.position; - targetVec.Scale(new Vector3(0.05f, 0.05f, 0)); + targetVec.Scale(new Vector3(followSpeed, followSpeed, 0)); transform.position = transform.position + targetVec; + + Camera.main.orthographicSize = Camera.main.orthographicSize * (1-zoomSpeed) + (minZoom + zoomFactor / 6f * (followThis.GetComponent().velocity.magnitude)) * zoomSpeed; } public void SetFollow(GameObject g) { followThis = g; var diff = (transform.position - followThis.transform.position); diff.Scale(new Vector3(1f, 1f, 0f)); - transform.position = transform.position - diff + (Vector3) (Random.insideUnitCircle) * Random.value * 5f; + transform.position = transform.position - diff + (Vector3) (Random.insideUnitCircle) * Random.value * startingDist; } } \ No newline at end of file diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 34e3402..9bf3273 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -32,7 +32,6 @@ public class PlayerMovement : MonoBehaviour { return; Vector3 speedVec = new Vector3(rb.velocity.x, rb.velocity.y, 0); - Camera.main.orthographicSize = Camera.main.orthographicSize * 0.95f + (5 + 4f/6f * (speedVec.magnitude)) * 0.05f; float speed = speedVec.magnitude; { // Forward diff --git a/Assets/graphics/textures/car.meta b/Assets/graphics/textures/car.meta new file mode 100644 index 0000000..8504594 --- /dev/null +++ b/Assets/graphics/textures/car.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9ec323b9157704d00a3409f8ea6e46b2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/graphics/textures/tmp.meta b/Assets/graphics/textures/tmp.meta new file mode 100644 index 0000000..7ebab68 --- /dev/null +++ b/Assets/graphics/textures/tmp.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df6e7833427b5497b92308fb6f54e552 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: