1
0
Fork 0

Camera movement

This commit is contained in:
Piegames 2018-04-23 14:12:06 +02:00
parent e7fd24f694
commit 79d4fe7ba5

View file

@ -7,26 +7,27 @@ public class CameraControl : MonoBehaviour {
[SerializeField]
private GameObject followThis;
private Vector3 offset;
void Start() {
Camera.main.orthographicSize = 6;
if ( followThis == null )
return;
offset = transform.position - followThis.transform.position;
}
void LateUpdate() {
if ( followThis == null )
return;
var target = followThis.transform.position; // + offset;
var target = followThis.transform.position;
var targetVec = target - transform.position;
targetVec.Scale(new Vector3(0.05f, 0.05f, 0));
targetVec.z = 0;
Camera.main.orthographicSize = 6 + targetVec.sqrMagnitude * 10;
transform.position = transform.position + targetVec;
targetVec.Scale(new Vector3(0.05f, 0.05f, 0));
}
public void SetFollow(GameObject g) {
followThis = g;
offset = transform.position - followThis.transform.position;
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;
}
}