Created
November 23, 2014 21:08
-
-
Save Zerophase/d400b6f8d6e061e15735 to your computer and use it in GitHub Desktop.
Jump Code
This file contains 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
public Vector3 Jump(bool pressed) | |
{ | |
return jumpAnimations[jumpComparision(pressed)].Invoke(); | |
} | |
private int jumpComparision(bool pressed) | |
{ | |
if (pressed && !savedPress && !hasJumped) | |
returnValue = (int)JumpComparison.ON_Press; | |
else if (pressed && jumpVelocity.y > 0.0f) | |
returnValue = (int)JumpComparison.RISING; | |
else if (Util.compareEachFloat(gravity.y, -1f)) | |
returnValue = (int)JumpComparison.DROPPING; | |
else if (Util.compareEachFloat(gravity.y, 0.0f)) | |
returnValue = (int)JumpComparison.LANDING; | |
savedPress = pressed; | |
return returnValue; | |
} | |
private Vector3 OnPress() | |
{ | |
jumpTimer = 0; | |
jumpVelocity = new Vector3(0f, 1.5f, 0f); | |
falling = false; | |
return jumpVelocity; | |
} | |
private Vector3 Rising() | |
{ | |
jumpTimer += Time.deltaTime; | |
jumpVelocity = (gravity * jumpTimer) + jumpVelocity; | |
falling = true; | |
return jumpVelocity; | |
} | |
private Vector3 Dropping() | |
{ | |
jumpTimer += Time.deltaTime; | |
jumpVelocity = gravity * jumpTimer; | |
return jumpVelocity; | |
} | |
private Vector3 Landing() | |
{ | |
jumpVelocity = Vector3.zero; | |
jumpTimer = 0f; | |
return jumpVelocity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment