- Home /
ROBLOX Like Camera Script
I have been looking over the internet for a script. But most of them did not work. Some worked but they didn't work the way i wanted to. I need a camera script where you can orbit, zoom and switch beetween first and third person by zooming. Can anyone link a tutorial or help me out? Thanks!
Answer by zixygamer · Jul 09, 2018 at 10:47 AM
Insert this to your Player GameObject. And insert your camera to TheCamera Field. using System.Collections; using System.Collections.Generic; using UnityEngine;
 public class PlayerCamera : MonoBehaviour {
     //define some constants
     private const float LOW_LIMIT = 0.0f;
     private const float HIGH_LIMIT = 85.0f;
 
     //these will be available in the editor
     public GameObject theCamera;
     public float followDistance = 5.0f;
     public float mouseSensitivityX = 4.0f;
     public float mouseSensitivityY = 2.0f;
     public float heightOffset = 0.5f;
 
 
     // Use this for initialization
     void Start () {
         //place the camera and set the forward vector to match player
         theCamera.transform.forward = gameObject.transform.forward;
         //hide the cursor and lock the cursor to center
         Cursor.visible = true;
         Cursor.lockState = CursorLockMode.None;
     }
 
     // Update is called once per frame
     void Update () {
 
         if(Input.GetMouseButton(1))
         {
             //if we are not paused, get the mouse movement and adjust the camera
             //position and rotation to reflect this movement around player
             Vector2 cameraMovement = new Vector2(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"));
 
             //first we place the camera at the position of the player + height offset
             theCamera.transform.position = gameObject.transform.position + new Vector3(0,heightOffset,0);
 
             //next we adjust the rotation based on the captured mouse movement
             //we clamp the pitch (X angle) of the camera to avoid flipping
             //we also adjust the values to account for mouse sensitivity settings
             theCamera.transform.eulerAngles = new Vector3(
                 Mathf.Clamp(theCamera.transform.eulerAngles.x + cameraMovement.y * mouseSensitivityY, LOW_LIMIT, HIGH_LIMIT),
                 theCamera.transform.eulerAngles.y + cameraMovement.x * mouseSensitivityX, 0);
 
             //then we move out to the desired follow distance
             theCamera.transform.position -= theCamera.transform.forward * followDistance;
         }
     }
 }
,Insert this script into your player. And insert your Camera into TheCamera Field
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerCamera : MonoBehaviour { //define some constants private const float LOW_LIMIT = 0.0f; private const float HIGH_LIMIT = 85.0f;
 //these will be available in the editor
 public GameObject theCamera;
 public float followDistance = 5.0f;
 public float mouseSensitivityX = 4.0f;
 public float mouseSensitivityY = 2.0f;
 public float heightOffset = 0.5f;
 // Use this for initialization
 void Start () {
     //place the camera and set the forward vector to match player
     theCamera.transform.forward = gameObject.transform.forward;
     //hide the cursor and lock the cursor to center
     Cursor.visible = true;
     Cursor.lockState = CursorLockMode.None;
 }
 // Update is called once per frame
 void Update () {
     if(Input.GetMouseButton(1))
     {
         //if we are not paused, get the mouse movement and adjust the camera
         //position and rotation to reflect this movement around player
         Vector2 cameraMovement = new Vector2(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"));
         //first we place the camera at the position of the player + height offset
         theCamera.transform.position = gameObject.transform.position + new Vector3(0,heightOffset,0);
         //next we adjust the rotation based on the captured mouse movement
         //we clamp the pitch (X angle) of the camera to avoid flipping
         //we also adjust the values to account for mouse sensitivity settings
         theCamera.transform.eulerAngles = new Vector3(
             Mathf.Clamp(theCamera.transform.eulerAngles.x + cameraMovement.y * mouseSensitivityY, LOW_LIMIT, HIGH_LIMIT),
             theCamera.transform.eulerAngles.y + cameraMovement.x * mouseSensitivityX, 0);
         //then we move out to the desired follow distance
         theCamera.transform.position -= theCamera.transform.forward * followDistance;
     }
 }
}
Answer by zixygamer · Jul 09, 2018 at 07:08 AM
Insert this to you gameobject or player. using System.Collections; using System.Collections.Generic; using UnityEngine;
 public class PlayerCamera : MonoBehaviour {
     //define some constants
     private const float LOW_LIMIT = 0.0f;
     private const float HIGH_LIMIT = 85.0f;
 
     //these will be available in the editor
     public GameObject theCamera;
     public float followDistance = 5.0f;
     public float mouseSensitivityX = 4.0f;
     public float mouseSensitivityY = 2.0f;
     public float heightOffset = 0.5f;
 
 
     // Use this for initialization
     void Start () {
         //place the camera and set the forward vector to match player
         theCamera.transform.forward = gameObject.transform.forward;
         //hide the cursor and lock the cursor to center
         Cursor.visible = true;
         Cursor.lockState = CursorLockMode.None;
     }
 
     // Update is called once per frame
     void Update () {
 
         if(Input.GetMouseButton(1))
         {
             //if we are not paused, get the mouse movement and adjust the camera
             //position and rotation to reflect this movement around player
             Vector2 cameraMovement = new Vector2(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"));
 
             //first we place the camera at the position of the player + height offset
             theCamera.transform.position = gameObject.transform.position + new Vector3(0,heightOffset,0);
 
             //next we adjust the rotation based on the captured mouse movement
             //we clamp the pitch (X angle) of the camera to avoid flipping
             //we also adjust the values to account for mouse sensitivity settings
             theCamera.transform.eulerAngles = new Vector3(
                 Mathf.Clamp(theCamera.transform.eulerAngles.x + cameraMovement.y * mouseSensitivityY, LOW_LIMIT, HIGH_LIMIT),
                 theCamera.transform.eulerAngles.y + cameraMovement.x * mouseSensitivityX, 0);
 
             //then we move out to the desired follow distance
             theCamera.transform.position -= theCamera.transform.forward * followDistance;
         }
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to make camera zooming with a range? [C#] 0 Answers
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
Trying to recreate the doodlejump camera c# 1 Answer
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                