JumpPhysics

m

(var)

(func)

void

Awake(){ ... }

Update(){ ... }

bool bCeiling = RaycastCollideVertical(Vector2.up);

CalculateMoveDirection();

transform.Translate(moveDirection * Time.deltaTime);

// move via transform component

CalculateMoveDirection(){ ... }

if(Input.GetButtonDown("Jump")){ ... }

if (allowDoubleJump && !HasDoubleJumped && HasJumpedOnce) { ... }

if (!IsHoldingJump && (IsGrounded || (allowDoubleJump && IsDoubleJumping && !HasDoubleJumped)) && !RaycastCollideVertical(Vector3.up)) { ... }

else if(Input.GetButtonUp("Jump")) { ... }

IsHoldingJump = false;

if(!IsGrounded){ ... }

// if airborne, apply gravity to current jump speed then add to movement vector

if (bCeiling) { ... }

// if hit ceiling, stop all upward movement.

jumpDirection = (jumpDirection.y > 0) ? new Vector2(0, 0) : jumpDirection;

IsMaxHeightReached = true;

if (allowVariableJumpHeight) { ... }

// check if we're at max height so we can apply gravity

if(AtMaxVariableJumpHeight()){ ... }

IsMaxHeightReached = true;

//apply gravity

if (!allowVariableJumpHeight){ ... }

jumpDirection += new Vector2(0, currentGravity);

//if not variable jump, just apply gravity

else if(IsMaxHeightReached || !IsHoldingJump){ ... }

jumpDirection += new Vector2(0, currentGravity);

//else MaxHeight must be reached or no longer holding jump to apply gravity

moveDirection += jumpDirection;

// moveDirection holds final value of movement delta

DebugRays(){ ... }

// draws all rays in up and down direction

bool

(delete)

AtMaxVariableJumpHeight(){ ... }

//changes max height based on if double jump is possible or not

RaycastCollideVertical(Vector3 direction){ ... }

//ray casting on left and right side

HitTagOrLayerObject(GameObject collisionObject){ ... }

//???

Vector2

GetJumpPowerVector(){ ... }

return (HasDoubleJumped) ? new Vector2(0, doubleJumpPower) : new Vector2(0, jumpPower);