Question by
pancadsaftaji25 · Nov 13, 2020 at 11:33 AM ·
cameracamera rotatecamera-look
Help me create camere collision for mobile
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyCamera : MonoBehaviour
{
public float Yaxis;
public float Xaxis;
public float RotationSensitivity = 8f;
public bool enableMobileInputs = false;
public Transform target;
public TouchField touchField;
float RotationMin=-40f;
float RotationMax=80f;
float smoothTime = 0.12f;
Vector3 targetRotation;
Vector3 currentVel;
private void Start()
{
if (enableMobileInputs)
RotationSensitivity = 0.2f;
}
void LateUpdate()
{
if (enableMobileInputs)
{
Yaxis += touchField.TouchDist.x * RotationSensitivity;
Xaxis -= touchField.TouchDist.y * RotationSensitivity;
}
else
{
Yaxis += Input.GetAxis("Mouse X") * RotationSensitivity;
Xaxis -= Input.GetAxis("Mouse Y") * RotationSensitivity;
}
Xaxis = Mathf.Clamp(Xaxis, RotationMin, RotationMax);
targetRotation = Vector3.SmoothDamp(targetRotation, new Vector3(Xaxis, Yaxis), ref currentVel, smoothTime);
transform.eulerAngles = targetRotation;
transform.position = target.position - transform.forward * 2f;
}
}
Comment
Your answer
Follow this Question
Related Questions
I cannot move my camera in the Game mode 0 Answers
Camera spawn rotate with object 0 Answers
Pivot Camera to Follow Mouse Position? 0 Answers