- Home /
The question is answered, right answer was accepted
MouseWheel Lerp Smoothing Problem
In below code, smoothing works very well with X and Y axises (w-a-s-d), but somehow i can not smooth the zoom in and out (z axis, mouse wheel) with this code. What am i doing wrong? Thanks in advance.
public float cameraMultiplierX, cameraMultiplierY, cameraMultiplierZ, cameraSmoothness;
private float camX, camY, camZ;
void Start ()
{
camX = 0;
camY = 0;
camZ = 0;
}
void Update()
{
Vector3 finalMovement = Vector3.zero;
/* -- Raw inputs -- */
float rawX = Input.GetAxis ("Horizontal") * cameraMultiplierX;
float rawY = Input.GetAxis ("Vertical") * cameraMultiplierY;
float rawZ = Input.GetAxis ("Mouse ScrollWheel") * cameraMultiplierZ;
/* -- Lerps -- */
camX = Mathf.Lerp (camX, rawX, cameraSmoothness * cameraMultiplierX);
camY = Mathf.Lerp (camY, rawY, cameraSmoothness * cameraMultiplierY);
camZ = Mathf.Lerp (camZ, rawZ, cameraSmoothness * cameraMultiplierZ);
/* -- Final application -- */
finalMovement = new Vector3 (camX, camY, camZ);
mainCamera.transform.Translate(finalMovement * Time.deltaTime);
}
Couple of things, what is the value of cameraSmoothness and camera$$anonymous$$ultiplier? Second, if you go to Input settigns (Edit->Project settings->Input), you can set the snap value to false so that it does the lerping naturally.
Snaps are all false already. And I tried many different numbers, huge ones, small ones, ordinary ones... But i just can't manage to smooth out the zoom in and out. Currently adjusted values are these in order of decleration: "50, 50, 500, 10".
Answer by fafase · Jun 29, 2015 at 03:53 AM
What is adjusted values? Does it mean cameraSmoothness and cameraMultiplier are 500 and 10?
In that case, it means your ratio of the lerp is 5000 while this value should be between 0 and 1.
$$anonymous$$an, you saved the day. I thought the "t" in arguments stands for "time". Thank you.