Skip to content

Commit c77549e

Browse files
committed
finished camera
1 parent 101cded commit c77549e

File tree

3 files changed

+244
-13
lines changed

3 files changed

+244
-13
lines changed

Assets/Scenes/testLvl.unity

Lines changed: 226 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/cameraFollow.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
using UnityEngine;
42

53
public class cameraFollow : MonoBehaviour
64
{
75

8-
public float speed = 40f;
6+
// selects targe to be fixed on
7+
public Transform target;
8+
public float smoothing = 0.12f;
99

10+
// because it is fixed to player, we want to move in from by 10 layers be default
11+
public Vector3 offset = new Vector3(0f,0f,-10f);
1012

11-
// Update is called once per frame
12-
void Update()
13-
{
14-
13+
void FixedUpdate() {
14+
Vector3 desiredP = target.position + offset;
15+
16+
// interpolate movement
17+
Vector3 smoothP = Vector3.Lerp(transform.position, desiredP, smoothing);
18+
transform.position = smoothP;
19+
20+
// will move in direction of target
21+
// comment out if you don't like the jitters
22+
transform.LookAt(target);
1523
}
24+
1625
}

Packages/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {
33
"com.unity.2d.sprite": "1.0.0",
44
"com.unity.2d.tilemap": "1.0.0",
5+
"com.unity.cinemachine": "2.5.0",
56
"com.unity.collab-proxy": "1.2.16",
67
"com.unity.ide.rider": "1.1.4",
78
"com.unity.ide.vscode": "1.1.4",

0 commit comments

Comments
 (0)