- Home /
 
 
               Question by 
               me16 · Jan 17, 2019 at 01:46 AM · 
                cameracamera-movementcamera rotateorbit3rd person camera  
              
 
              How to set horizon level for camera orbit script?
I have a camera orbit script for a 3rd person game, but I don't want my camera to be able to go through the floor. Here's my code: using UnityEngine; using System.Collections;
public class SmoothFollow : MonoBehaviour { public float speed = 8f; public float distance = 3f; public Transform target; private Vector2 input; private float thing; public Rigidbody rb; private void Start() { rb = GetComponent(); } void Update() {
     thing = Input.GetAxis("Mouse Y");
     if (Input.GetButton("Fire2"))
     {
         input += new Vector2(Input.GetAxis("Mouse X") * speed, thing * speed);
     }
     Quaternion rotation = Quaternion.Euler(input.y, input.x, 0);
     Vector3 position = target.position - (rotation * Vector3.forward * distance);
     transform.localRotation = rotation;
     transform.localPosition = position;
 }
 
               }
               Comment
              
 
               
              Your answer