- Home /
Camera Smoothness issue.. Please help..
Hi Guys, I have GUI.Repeat Button to control my camera in OnGUI() in GUIHandler.cs In CameraHandler.cs, i have an update loop, which is processing the deltaX & deltaY sent by GUIHandler.
Problem with below code is i m not getting a smoothness while rotating camera. its lagging. Please tell me whats wrong with this code?
GUIHandler.cs
if (GUI.RepeatButton(cameraHandlerBounds, textureCamera, GUIStyle.none))
{
Vector3 mousePosition = Input.mousePosition;
mousePosition.y = Screen.height - mousePosition.y;
//Debug.Log("Clicked the button with an image: " + mousePosition + " center: " + cameraHandlerBoundsCenter + " MaxDist: " + maxDistance);
distanceCovered = Vector3.Distance(mousePosition, cameraHandlerBoundsCenter);
if (distanceCovered > maxDistance.x)
{
Debug.Log("Out of Bound");
if (isControlInbound)
isControlInbound = false;
}
else
{
deltaX = mousePosition.x - cameraHandlerBoundsCenter.x ;
deltaY = cameraHandlerBoundsCenter.y - mousePosition.y;
deltaX = Mathf.Clamp(deltaX, deltaXPre - 0.15f, deltaXPre + 0.15f);
deltaY = Mathf.Clamp(deltaY, deltaYPre - 0.15f, deltaYPre + 0.15f);
deltaXStore = deltaX;
deltaYStore = deltaY;
if (!isControlInbound)
isControlInbound = true;
deltaXPre = deltaXStore;
deltaYPre = deltaYStore;
cameraHandlerRef.deltaX = deltaX;
cameraHandlerRef.deltaY = deltaY;
}
}
CameraHandler.cs
float rotationX = transform.localEulerAngles.y + (deltaX * Time.deltaTime); //Input.GetAxis("Mouse X") * sensitivityX;
rotationY += (deltaY * Time.deltaTime );
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
Comment
Your answer

Follow this Question
Related Questions
camera rotation 0 Answers
Camera rotation vmware 0 Answers
Move the Object to Camera respective. 1 Answer
easing camera rotation after mouse up? 0 Answers