i try to create free look camera i was follow tutorial on YouTube everything work fine except i noticed that the rotation value about the y axis which is stored in float variable the angle value is getting Continue to accumulate i try to clamp it but its result in undesired behavior i also try the mathf.repeat the same i tried to zero the angle if it larger than 360 but this create another instant rotation in the opposite dir , i use the += operator which i think it causes this if I am not mistaken
my question dose this affect the performance i target mobile device's in general
If it affects performance, how should I deal with this problem?
thank you for any help really
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera : MonoBehaviour
{
public Transform target;
public float destotarget;
public float sensetivity;
public float smoothTime;
public float yaw;
public float pitch;
public Vector2 minandmax = new Vector2(34, 54);
public Vector3 currnetrot;
public Vector3 velocitysmooth;
// Update is called once per frame
void LateUpdate()
{
yaw += Input.GetAxis("Mouse X") * sensetivity;
pitch += Input.GetAxis("Mouse Y") * sensetivity;
pitch = Mathf.Clamp(pitch, minandmax.x, minandmax.y);
currnetrot = Vector3.SmoothDamp(currnetrot, new Vector2(pitch, yaw), ref velocitysmooth, smoothTime);
transform.eulerAngles = currnetrot;
transform.position = target.position - transform.forward * destotarget;
}
}
This shouldn't effect the performance much, but the only way to ever know is to profile: