Skip to content

Instantly share code, notes, and snippets.

@Geokureli
Created February 21, 2019 19:15
Show Gist options
  • Save Geokureli/ad91c450a356ef4b7597641e8bae741a to your computer and use it in GitHub Desktop.
Save Geokureli/ad91c450a356ef4b7597641e8bae741a to your computer and use it in GitHub Desktop.
// Basic jump properties
/** Jump height when button in held */
inline static var MAX_HEIGHT = 110;
/** Jump height when button in tapped */
inline static var MIN_HEIGHT = 30;
/** Seconds it takes to reach the apex of the max jump */
inline static var TIME_TO_MAX = 0.35;
/** Horizontal distance traveled if at max speed */
inline static var JUMP_WIDTH = 170;
// METHOD 1
// set initial jump speed to reach min,
// hold it to maintain the jump speed long enough to reach max height
inline static var TIME_TO_MIN = 2 * TIME_TO_MAX * MIN_HEIGHT / (MIN_HEIGHT + MAX_HEIGHT);
inline static var GRAVITY = 2 * MIN_HEIGHT / TIME_TO_MIN / TIME_TO_MIN;
inline static var JUMP_Y_SPEED = -2 * MIN_HEIGHT / TIME_TO_MIN;
/** Max time you can hold the jump button for a higher jump */
inline static var JUMP_TIME = (MAX_HEIGHT - MIN_HEIGHT) / -JUMP_Y_SPEED;
// METHOD 2
// set initial jump speed to reach max,
// on key release use higher gravity
inline static var GRAVITY = 2 * MAX_HEIGHT / TIME_TO_MAX / TIME_TO_MAX;
inline static var FAST_GRAVITY = JUMP_Y_SPEED * JUMP_Y_SPEED / MIN_HEIGHT / 2;
inline static var JUMP_Y_SPEED = -2 * MAX_HEIGHT / TIME_TO_MAX;
// Horizontal speed
inline static var JUMP_X_SPEED = JUMP_WIDTH / TIME_TO_MAX / 2;
/** Time from full speed to stop */
inline static var AIR_STOP_TIME = TIME_TO_MAX;
inline static var AIR_X_ACCEL = JUMP_X_SPEED / AIR_STOP_TIME;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment