Browse Source

Improved camera follower y tracking

jeff
Jeff 2 years ago
parent
commit
4ab8037bb9
2 changed files with 6 additions and 4 deletions
  1. BIN
      Assets/Scenes/Level 2.unity
  2. +4
    -2
      Assets/Scripts/CameraFollower.cs

BIN
Assets/Scenes/Level 2.unity (Stored with Git LFS) View File

size 441491

+ 4
- 2
Assets/Scripts/CameraFollower.cs View File

@ -9,6 +9,8 @@ public class CameraFollower : MonoBehaviour
[SerializeField] private float m_FollowStrength = 3f; [SerializeField] private float m_FollowStrength = 3f;
[SerializeField] private bool m_FollowX = true; [SerializeField] private bool m_FollowX = true;
[SerializeField] private bool m_FollowY = false; [SerializeField] private bool m_FollowY = false;
[SerializeField] private float m_OffsetX = 0f;
[SerializeField] private float m_OffsetY = 2.0f;
private Camera m_Camera; private Camera m_Camera;
@ -22,8 +24,8 @@ public class CameraFollower : MonoBehaviour
if(Mathf.Abs(Player.transform.position.x - m_Camera.transform.position.x) > m_FollowStrength) if(Mathf.Abs(Player.transform.position.x - m_Camera.transform.position.x) > m_FollowStrength)
{ {
m_Camera.transform.Translate( m_Camera.transform.Translate(
m_FollowX ? (m_FollowStrength + Player.transform.position.x - m_Camera.transform.position.x) * Time.deltaTime : 0,
m_FollowY ? (m_FollowStrength + Player.transform.position.y - m_Camera.transform.position.y) * Time.deltaTime : 0,
(m_FollowX ? (m_FollowStrength + Player.transform.position.x - m_Camera.transform.position.x - m_OffsetX) * Time.deltaTime : 0),
(m_FollowY ? (m_FollowStrength + Player.transform.position.y - m_Camera.transform.position.y - m_OffsetY) * Time.deltaTime : 0),
0); 0);
} }
} }

Loading…
Cancel
Save