- Home /
Clamping Transform.localPosition. Codes Inside
Hello Everyone. Im Trying to Clamp Object position while Lerping. What can be the solution?
IEnumerator Jump()
{
float elapse_time = 0;
while (elapse_time < 1.3f)
{
elapse_time += Time.deltaTime;
Vector3 startPos = new Vector3(0, transform.localPosition.y, 0);
Vector3 EndPos = new Vector3(0, transform.localPosition.y+ offsetY, 0);
Vector3 LastPos = transform.localPosition;
LastPos.y = Mathf.Clamp(transform.localPosition.y, .1f, 1.5f);
transform.localPosition = LastPos;
LastPos = Vector3.Lerp(startPos, EndPos,Time.deltaTime*timeMultiplier);
yield return null;
}
}
Comment
I'm triying to lerp a gameObject in the y axis with the "input.Getaxis". But it lerps much more than i want the gameObject should be. And im trying to make it clamp like 1.5m in the y axis.
make sure that Time.deltaTime * timeMultiplier value must be in between 0 and 1. if you wanna slow down the lerp, then make its value approx. near 0
Your answer
