- Home /
Question by
Bionicghost · Feb 06, 2017 at 07:48 AM ·
cameraps3
How to make a camera move smoothly according to a controller stick, and return to center when the stick is not moved?
I am making a 1st person space dog-fighting game, with elements of the UI scattered around the cockpit, so i want the camera to rotate within certain angles with the right stick of the controller, but snap back to the center when i let go. I already set the axes "CamHor" and "CamVert" to the 4th and 5th axes on my controller. So far i've got:
public class CameraController : MonoBehaviour {
public int maxAngleX=90;
public int maxAngleY=30;
void LateUpdate()
{
float rotateY = Input.GetAxis("CamHor") * maxAngleX=;
float rotateX = Input.GetAxis("CamVert") * maxAngleY=;
transform.rotation = Quaternion.Euler(rotateX,rotateY,0);
}
But it moves too quickly, and i wish to make the movement smoother. Any suggestions?
Comment
Oh. I found the answer.
public class CameraController : $$anonymous$$onoBehaviour {
public int maxAngleX;
public int maxAngleY;
public float camSmooth = 2.0F;
void LateUpdate()
{
float rotateY = Input.GetAxis("CamHor") * maxAngleX;
float rotateX = Input.GetAxis("CamVert") * maxAngleY;
Quaternion camTarget = Quaternion.Euler(rotateX, rotateY, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, Time.deltaTime * camSmooth);
}
}