- Home /
Lerp between two angles
Hello,
I am making a hammer rotating around its X axis and its child (pivot) swinging around its Y axis. But I have 3 problems:
It will not lerp within the given time from -angleMax to angleMax.
it will not rotate based on timeScale multiplier; it still rotates until it reaches angleMax.
The progress value should describe the progress from angleMax (0) to -angleMax (1) and vice Versa. But the value is too large, so I divided with 75.
private var pivot : Transform; public var rotSpeed : float = 18f; public var angleMax : float = 75f; public var lerpTime : float = 8f; public var progress : float; public var currentX : float; public var isReversing : boolean; function Start () { pivot = transform.GetChild(0); pivot.rotation.eulerAngles.x = angleMax; currentX = pivot.rotation.eulerAngles.x; } function Update () { transform.RotateAround(transform.position, Vector3.up, rotSpeed * Time.deltaTime * Time.timeScale); if(progress < 1f){ progress += (Time.deltaTime / lerpTime) * Time.timeScale; } else { progress = 0f; isReversing = !isReversing; } if(!isReversing){ currentX = Mathf.Lerp(currentX, -angleMax, progress/75); } else { currentX = Mathf.Lerp(currentX, angleMax, progress/75); } pivot.localRotation.eulerAngles.x = currentX; }
Answer by Arkaid · Jul 06, 2016 at 01:52 AM
Might be because you're lerping from currentX (instead of -angleMax) to angleMax. Try to see if this fixes it:
currentX = Mathf.Lerp(-angleMax, angleMax, progress);
Your answer
![](https://koobas.hobune.stream/wayback/20220612084252im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RotateAround over a set period of time 0 Answers
Rotate 90 degrees over time with Parabolic Easing. 1 Answer
Rotate an object using joystick 1 Answer
Rotate 90 over time on mouseDown 2 Answers
from Quaternion to RotateAround 1 Answer