Skip to content

Instantly share code, notes, and snippets.

@thallippoli
Last active August 29, 2015 14:01
Show Gist options
  • Save thallippoli/03e005fb5bfea3a98f0d to your computer and use it in GitHub Desktop.
Save thallippoli/03e005fb5bfea3a98f0d to your computer and use it in GitHub Desktop.
Jump as Update and as a coroutine
bool mJumping;
void JumpCo()
{
float jumpProgress = 0.0f;
Vector3 jumpStartPos = transform.position;
mJumping = True;
while( mJumping && jumpProgress < 1.0f )
{
jumpProgress = Mathf.Clamp01( JumpProgress + Time.deltaTime / JUMP_TIME );
transform.position = jumpStartPos + EvaluateJump( jumpProgress );
yield return null; // wait till end of frame
}
mJumping = false;
}
float mJumpProgress; // [ 0, 1 ]
Vector3 mJumpStartPos;
bool mJumping;
void BeginJump()
{
mJumpProgress = 0.0f;
mJumpStartPos = transform.position;
mJumping = True;
}
void UpdateJump()
{
if( !mJumping )
return;
if( mJumpProgress == 1.0f )
{
mJumpProgress = Mathf.Clamp01( mJumpProgress + Time.deltaTime / JUMP_TIME );
transform.position = mJumpStartPos + this.EvaluateJump( mJumpProgress );
return;
}
mJumping = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment