- Home /
Question by
GafferSystems · Jun 13, 2019 at 03:14 PM ·
updatecamera-movementframeratepan
Camera flies far away if lag spike occurs
I use translate to pan the camera holding the middle mouse button. It works great until there is a lag spike, then it seems to add up and get a crazy speed, and when the short lag is over it sends the camera off far away. Is there a better way to move the camera to avoid it being affected by the framerate?
void Update() {
// Pan camera by holding middle mouse-button
if (Input.GetMouseButton(2)) {
transform.Translate(
(-Input.GetAxis("Mouse X") * panSpeed) * Time.deltaTime,
(-Input.GetAxis("Mouse Y") * panSpeed) * Time.deltaTime,
0, Space.Self
);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612203137im_/https://answers.unity.com/themes/thub/images/avi.jpg)