Skip to content

Instantly share code, notes, and snippets.

@Mazday21
Created August 21, 2022 11:57
Show Gist options
  • Save Mazday21/5111343cb730093c0dd18783beba694a to your computer and use it in GitHub Desktop.
Save Mazday21/5111343cb730093c0dd18783beba694a to your computer and use it in GitHub Desktop.
private IEnumerator Jump()
{
_animator.SetBool("Grounded", false);
_coroutineAllowed = false;
_swipeTime = 0;
Vector3 startPosition = transform.position;
Vector3 endPosition = new Vector3(startPosition.x, transform.position.y + _jumpHeight, transform.position.z + _speed * _jumpDuration);
while (_swipeTime < _jumpDuration / 2)
{
_swipeTime += Time.deltaTime;
transform.position = Vector3.Lerp(startPosition, endPosition, _swipeTime / _jumpDuration);
yield return null;
}
StartCoroutine(JumpDown());
}
private IEnumerator JumpDown()
{
_swipeTime = 0;
Vector3 startPosition = transform.position;
Vector3 endPosition = new Vector3(startPosition.x, transform.position.y - _jumpHeight, transform.position.z + _speed * _jumpDuration);
while (_swipeTime < _jumpDuration / 2)
{
_swipeTime += Time.deltaTime;
transform.position = Vector3.Lerp(startPosition, endPosition, _swipeTime / _jumpDuration);
yield return null;
}
_animator.SetBool("Grounded", true);
_coroutineAllowed = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment