Camera Follow X Axis Help
Hey guys!I want camera to follow player only on X axis but also to have nice offset and smoothing (not to start following now, but to wait a bit) , I’ve watched some tutorial on it, and it works fine, but on Y too, and I want only on X, as I said, here is a script:using UnityEngine; using System.Collections; public class CameraScript : MonoBehaviour { public Transform target; //player transform public float smoothing; Vector3 offset; // Use this for initialization void Start () { offset = transform.position - target.position; } // Update is called once per frame void FixedUpdate () { Vector3 targetCamPos = target.position + offset; transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime); } }
using UnityEngine;
using System.Collections;
public class CameraScript : MonoBehaviour { public Transform target;
public float smoothing; Vector3 offset; ;
// Use this for initialization
void Start () {
offset = transform.position - target.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 targetCamPos = target.position + offset; transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612064747im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Let the Camera Face the middle of the Map while still following the Player? 1 Answer
Camera Jitters When Displacing and Rotating Smoothly 0 Answers
Smoth LookAt Unity c# 0 Answers
Camera Tracking 1 Answer
How to prevent camera going into terrain 0 Answers