- Home /
Camera doesnt allow me to change its position / rotation (help)
I've made a camera script, but i changed the camera transform to a gameobject, to prevent it from shaking (friction), so far this has worked, but it has lead me to some problems. 1. I cannot changed the cameras position, 2. I cannot change its rotation (from the looking script), i somehow got around this but i completely forgot how i did it. The script i want to make for it is a shaking script, when theres an explosion, the camera shakes, or when your driving a vehicle. Heres my camera script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamLook : MonoBehaviour
{
public bool canLook = true;
public bool cursVis;
public bool locked;
public bool useSmoothSpeed;
public float floatSpeed = 10.0f;
public float value = 0.0f;
public float currentXRot;
public float currentYRot;
public float xRot;
public float yRot;
public float vRotX;
public float vRotY;
public float vRotZ;
[Range(1, 90)]
public float clampDegreeUp = 90.0f;
[Range(-1, -90)]
public float clampDegreeDown = -90.0f;
public float sensitivity = 8.0f;
public float smoothDamp = 0.1f;
public GameObject player;
public Transform look;
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
look = GameObject.Find("Camera_Transform").transform;
}
void Update()
{
MoveCamera();
RotateCamera();
}
void MoveCamera()
{
if (useSmoothSpeed)
{
transform.position = Vector3.Lerp(new Vector3(look.position.x, transform.position.y, look.position.z), new Vector3(look.position.x, look.position.y, look.position.z), Time.deltaTime * floatSpeed);
}
else
{
transform.position = look.position;
}
}
void RotateCamera()
{
if (canLook)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
value = 0.0f * Time.deltaTime;
Vector3 vec = Vector3.zero;
xRot -= Input.GetAxis("Mouse Y") * sensitivity;
yRot += Input.GetAxis("Mouse X") * sensitivity;
xRot = Mathf.Clamp(xRot, clampDegreeDown, clampDegreeUp);
currentXRot = Mathf.SmoothDamp(currentXRot, xRot, ref vRotX, smoothDamp);
currentYRot = Mathf.SmoothDamp(currentYRot, yRot, ref vRotY, smoothDamp);
transform.rotation = Quaternion.Euler(currentXRot, currentYRot, 0);
}
if (!canLook)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
}
Answer by Aearow · Jul 10, 2018 at 05:10 AM
Try link text
very nice video tutorial about what your trying to do ( I was gonna type a script but I think you will learn more if you watch this video.)
Oh , hold up this video won't be very useful, never $$anonymous$$d , you can watch it if you want but , it doesn't cover your problems , sorry that I cannot help you.
literally was following it before you suggested, thats why i made this post XD