Question by
Itchiyo · Jun 18, 2021 at 02:22 PM ·
playerisometricmain camera
Camera doesn't follow the player
Hi, I have an issue with my Main camera in my project : First of all, my main camera doesn't find the tag on my gameobject even with the "FindGameObjectWithTag" And my main camera act very weird, like i change the position on my main camera on the unity scene, and once play the game, the camera came back at the initial position I really don't understand with it did that. Here the code :
public class CameraController : MonoBehaviour
{
private Transform target;
[SerializeField] private float smoothSpeed;
[SerializeField] private float minX, maxX, minY, maxY;
private void Awake()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
private void LateUpdate()
{
// Smoothly move Camera
// Lerp : first parameter => current position
// second parameter, => Target Position
// third parameter => speed
transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x, target.position.y,
transform.position.z), smoothSpeed * Time.deltaTime);
transform.position = new Vector3(Mathf.Clamp(transform.position.x, minX, maxX),
Mathf.Clamp(transform.position.y, minY, maxY),
transform.position.z);
}
}
Comment