Camera movement
This commit is contained in:
parent
e7fd24f694
commit
79d4fe7ba5
1 changed files with 8 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue