Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

i need help in cam rotation

sry this code is big but i really need help (again :D)

so this is not code i came up with but i kinda copied it but.

when i entered the code in unity and started playing camera started rotating in Y Axis it self and it was not stoping, i tryed looking for problem but could not find it so i would appreciate if anyone could help me out.




using UnityEngine;


public class cameramovement : MonoBehaviour

{

public float CameraMoveSpeed = 120f;

public GameObject CameraFollowObj;

Vector3 FollowPOS;

public float clampAngle = 80f;

public float inputSensitivity = 150;

public GameObject CameraObj;

public GameObject PlayerObj;

public float camDistanceXToPlayer;

public float camDistanceYToPlayer;

public float camDistanceZToPlayer;

public float mouseX;

public float mouseY;

public float finalInputX;

public float finalInputZ;

public float smoothX;

public float smoothY;

private float rotY = 0f;

private float rotX = 0f;

  // Start is called before the first frame update

  void Start(){

   Vector3 rot = transform.localRotation.eulerAngles;

   rotY = rot.y;

   rotX = rot.x;

   Cursor.lockState = CursorLockMode.Locked;

   Cursor.visible = false;

  }

  // Update is called once per frame

  void Update()

  {

  float inputX = Input.GetAxis ("RightStickHorizontal");

  float inputZ = Input.GetAxis ("RightStickVertical");

  mouseX = Input.GetAxis ("Mouse X");

  mouseY = Input.GetAxis ("Mouse Y");

  finalInputX = inputX + mouseX;

  finalInputZ = inputZ + mouseY;

  rotY += finalInputX + inputSensitivity * Time.deltaTime;

  rotX += finalInputZ + inputSensitivity * Time.deltaTime;

  rotX = Mathf.Clamp (rotX, -clampAngle, clampAngle);

  Quaternion localRotation = Quaternion.Euler (rotX, rotY, 0f);

  transform.rotation = localRotation;

  }



  void LateUpdate(){

   CameraUpdater();

  }


  void CameraUpdater() {

   Transform target = CameraFollowObj.transform;

   float step = CameraMoveSpeed * Time.deltaTime;

   transform.position = Vector3.MoveTowards (transform.position, target.position, step);

  }

}

Sign In or Register to comment.