Lerp sequence Coroutine issues
Hello! I am trying to move the IK of the hand of my 2D character seamlessly to and from aiming.
I am starting this coroutine in a FixedUpdate function
I want the sequence of lerps to be as simple as idle-to-holster-to-aim, and to hold on aim until i let go of the aim button, then to return to-holster-to-idle
The biggest issue at hand is that this code froze Unity and i had to force restart it, so there must be a game-breaking loop. Besides that, the lerps work great on their own
IEnumerator AimWeapon()
{
while (Vector3.Distance(hand_ik_R.transform.position, holster.transform.position) > 0.05f && !shouldAim)
{
hand_ik_R.transform.position = Vector3.Lerp(hand_ik_R.transform.position, holster.transform.position, aimSpeed * Time.deltaTime);
yield return null;
}
shouldAim = true;
yield return new WaitForSeconds(.3f);
while (shouldAim)
{
pistolScript.isAimed = true;
pistol.transform.position = Vector3.Lerp(pistol.transform.position, handAim_R.transform.position, aimSpeed * 5 * Time.deltaTime);
hand_ik_R.transform.position = Vector3.Lerp(hand_ik_R.transform.position, new Vector2(aimTarget.x, aimTarget.y), (aimSpeed / 2) * Time.deltaTime);
hand_ik_L.transform.position = Vector3.Lerp(hand_ik_L.transform.position, handAim_R.transform.position, aimSpeed * 20 * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
Jerky Lerp animation on iOS devices using IEnumerator. Any ideas? 0 Answers
Movement for GameObject[] in arrays jittery when using Lerp in Coroutine 0 Answers
How do multiple objects in sequence from a queue? 0 Answers
How can I change "IK position weight" of finalIK ? 0 Answers
How to rotate smoothly 0 Answers