- Home /
Lerp scale values on mouse scroll wheel
I am able to scale on mouse scroll for that I have written
transform.localScale.z += Input.GetAxis("Mouse ScrollWheel")*Mathf.Abs(transform.localScale.z);
but How can I lerp the localscale value?
Answer by robertbu · May 14, 2013 at 04:20 PM
'desiredScale' needs to be initialized to to transform.localScale.z in Start(). Then in Update() you can do something like:
desiredScale += Input.GetAxis("Mouse ScrollWheel")*Mathf.Abs(transform.localScale.z);
transform.localScale.z = Mathf.Lerp(transform.localScale.z, desiredScale, Time.deltaTime * speed);
'speed' you define and controls how quickly it will Lerp().
I used your scroll wheel code here which is a bit strange in that the amount of the zoom will vary with the scale. If you don't want that, put a constant in instead of the Mathf.Abs().
Your answer
Follow this Question
Related Questions
Issue lerping localscale 1 Answer
How to Scale an object up and down over time? 5 Answers
How to use WaitForSeconds inside IF / Else If statement? 1 Answer
Vector3.Lerp on a localScale 2 Answers
How to Lerp localScale? 1 Answer