unity3d - Smooth camera rotation unity -
i create third person camera. camera move in sync mouse move. create script camera move, work when speed high starts shake.
how force camera move smooth?
vector3 rotation = new vector3(); rotation = this.transform.rotation.eulerangles; float ver = input.mouseposition.y - mouse_position.y; difference_y = difference_y ?? ver; rotation.y += (float)(((input.mouseposition.x - mouse_position.x) / one_degree_per_pixel_hor)); rotation.x += (float)((-(input.mouseposition.y - mouse_position.y) / one_degree_per_pixel_ver)); rotation.z = 0; if (difference_y != 0) { // forward tilt if (difference_y < 0) { if (rotation.x > max_slope_forward && rotation.x < max_slope_back) rotation.x = max_slope_forward; } // tilt else { if (rotation.x < max_slope_back && rotation.x > max_slope_forward && rotation.x != max_slope_forward) rotation.x = max_slope_back; } } difference_y = ver; this.transform.rotate(new vector3(-input.getaxis("mouse y"), input.getaxis("mouse x"), 0),time.deltatime*speedrotation); rotation = this.transform.rotation.eulerangles; rotation.z = 0; this.transform.rotation = quaternion.euler(rotation); mouse_position = input.mouseposition;
i suggest use linear interpolation (lerp function) suggest jinji in comment.
here official tutorial
the lerp function change value from
value to
smoothly @ interval time.
lerp(float from, float to, float time)
with code, code this
// save original rotation orgrotation = this.transform.rotation.eulerangles; rotation = orgrotation; // stuff here this.transform.rotation = quaternion.lerp(orgrotation, quaternion.euler(rotation), 0.5f);
Comments
Post a Comment