1
0
Fork 0

Improved camera

This commit is contained in:
Piegames 2018-04-23 15:12:49 +02:00
parent 55d6feae55
commit 25059da219
4 changed files with 32 additions and 5 deletions

View file

@ -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<Rigidbody2D>().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;
}
}

View file

@ -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

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ec323b9157704d00a3409f8ea6e46b2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: df6e7833427b5497b92308fb6f54e552
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: