diff --git a/Assets/Scripts/CameraController.cs b/Assets/Scripts/CameraController.cs index a58c9ff..a8e5a88 100644 --- a/Assets/Scripts/CameraController.cs +++ b/Assets/Scripts/CameraController.cs @@ -4,15 +4,15 @@ using UnityEngine; public class CameraController : MonoBehaviour { - // Start is called before the first frame update - void Start() - { - - } + public Transform cam; // Reference to the camera's Transform + public Transform player; // Reference to the player's Transform + public float height = 5f; // Height offset of the camera above the player // Update is called once per frame void Update() { - + // Update the camera position to follow the player while maintaining the height + Vector3 newCameraPosition = new Vector3(player.position.x, player.position.y + height, player.position.z); + cam.position = newCameraPosition; } } diff --git a/Assets/Scripts/EnemyMovement.cs b/Assets/Scripts/EnemyMovement.cs index 0e655b2..5d1f77c 100644 --- a/Assets/Scripts/EnemyMovement.cs +++ b/Assets/Scripts/EnemyMovement.cs @@ -27,14 +27,13 @@ public class EnemyMovement : MonoBehaviour [Header("Spawn")] public float radius = 5f; - public Vector3 center = new Vector3(0f, 0f, 0f); void Start() { float randomAngle = UnityEngine.Random.Range(0f, 2 * Mathf.PI); // Calculate the point on the perimeter of the circle - Vector3 point = center + new Vector3(Mathf.Cos(randomAngle) * radius, 0.6f, Mathf.Sin(randomAngle) * radius); + Vector3 point = player.position + new Vector3(Mathf.Cos(randomAngle) * radius, 0.6f, Mathf.Sin(randomAngle) * radius); enemy.position = point; if (movementType == MovementTypes.ThroughPlayer) @@ -45,7 +44,7 @@ public class EnemyMovement : MonoBehaviour } // Update is called once per frame - void Update() + void FixedUpdate() { if (movementType == MovementTypes.Line) { diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index a3158e0..d93389c 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -55,7 +55,7 @@ public class PlayerController : MonoBehaviour } } - void Update() + void FixedUpdate() { Vector3 moveDirection = GetPlayerDirection().normalized;