Last active
August 29, 2015 14:01
-
-
Save thallippoli/03e005fb5bfea3a98f0d to your computer and use it in GitHub Desktop.
Jump as Update and as a coroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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