Hello I am seeking help with my camera. I want the camera to follow the player but not while it’s jumping. So the y coordinate is equal to zero, whilst the x and z variables follow the player’s transform position. Here’s the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollowScript : MonoBehaviour
{
public Transform PlayerTransform;
private Vector3 _cameraOffset;
//[Range(0.01f, 1.0f)]
public float SmoothFactor = 0.5f;
public bool LookAtPlayer = false;
// Use this for initialization
void Start()
{
_cameraOffset = transform.position - PlayerTransform.position;
}
// LateUpdate is called after Update
void Update()
{
Vector3 newPos = PlayerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
if (LookAtPlayer)
transform.LookAt(PlayerTransform);
}
}