public override void Execute(GameObject agent, MovementValues movementValues) { if (Input.GetKey(keycode)) { agent.GetComponent <Rigidbody>().velocity += CalculateVelocityVector(agent, movementValues); } }
private void JumpVelocityActivity() { if (JumpPushed && // If the jump button was pushed CurrentMovement.JumpVelocity > 0 && // the current movement variable has a non-zero jump velocity (mIsOnGround || AfterDoubleJump == null || (AfterDoubleJump != null && mHasDoubleJumped == false)) ) { mTimeJumpPushed = CurrentTime; this.YVelocity = CurrentMovement.JumpVelocity; mValuesJumpedWith = CurrentMovement; if (mCurrentMovement == AirMovement) { mHasDoubleJumped = true; } } double secondsSincePush = CurrentTime - mTimeJumpPushed; if (mValuesJumpedWith != null && secondsSincePush < mValuesJumpedWith.JumpApplyLength && (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpDown) ) { this.YVelocity = mValuesJumpedWith.JumpVelocity; } if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold && (!JumpDown || mHitHead) ) { mValuesJumpedWith = null; } }
public Vector3 CalculateVelocityVector(GameObject agent, MovementValues movementValues) { if (movementValues.isSprinting) { return(movementValues.moveSpeed * movementValues.sprintMultiplier * agent.transform.right); } else { return(movementValues.moveSpeed * agent.transform.right); } }
/// <summary> /// Applies the jump input to control vertical velocity and state. /// </summary> private void ApplyJumpInput() { bool jumpPushed = JumpInput.WasJustPressed && InputEnabled; bool jumpDown = JumpInput.IsDown && InputEnabled; if (jumpPushed && CurrentMovement.JumpVelocity > 0 && (IsOnGround || AfterDoubleJump == null || (AfterDoubleJump != null && mHasDoubleJumped == false) || (AfterDoubleJump != null && AfterDoubleJump.JumpVelocity > 0) ) ) { mTimeJumpPushed = CurrentTime; this.YVelocity = CurrentMovement.JumpVelocity; mValuesJumpedWith = CurrentMovement; if (JumpAction != null) { JumpAction(); } if (CurrentMovementType == MovementType.Air) { mHasDoubleJumped = true; } } double secondsSincePush = CurrentTime - mTimeJumpPushed; if (mValuesJumpedWith != null && secondsSincePush < mValuesJumpedWith.JumpApplyLength && (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpInput.IsDown) ) { this.YVelocity = mValuesJumpedWith.JumpVelocity; } if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold && (!JumpInput.IsDown || mHitHead) ) { mValuesJumpedWith = null; } this.YVelocity = Math.Max(-CurrentMovement.MaxFallSpeed, this.YVelocity); }
public override void Execute(GameObject agent, MovementValues movementValues) { if (movementValues.sprintingIsAToggle) { if (Input.GetKeyDown(keycode)) { movementValues.isSprinting = !movementValues.isSprinting; } } else { if (Input.GetKeyDown(keycode)) { movementValues.isSprinting = true; } if (Input.GetKeyUp(keycode)) { movementValues.isSprinting = false; } } }
private void JumpVelocity() { if (JumpPushed && CurrentMovement.JumpVelocity > 0 && (mIsOnGround || AfterDoubleJump == null || (AfterDoubleJump != null && mHasDoubleJumped == false)) ) { mTimeJumpPushed = CurrentTime; this.YVelocity = CurrentMovement.JumpVelocity; mValuesJumpedWith = CurrentMovement; if (CurrentMovementType == MovementType.Air) { mHasDoubleJumped = true; } } double secondsSincePush = CurrentTime - mTimeJumpPushed; if (mValuesJumpedWith != null && secondsSincePush < mValuesJumpedWith.JumpApplyLength && (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpDown) ) { this.YVelocity = mValuesJumpedWith.JumpVelocity; } if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold && (!JumpDown || mHitHead) ) { mValuesJumpedWith = null; } this.YVelocity = Math.Max(-CurrentMovement.MaxFallSpeed, this.YVelocity); }
public void DetermineMovementValues() { if (mIsOnGround) { mHasDoubleJumped = false; if (CurrentMovement == AirMovement || CurrentMovement == AfterDoubleJump) { mCurrentMovement = GroundMovement; } } else { if (CurrentMovement == GroundMovement) { mCurrentMovement = AirMovement; } } if (mCurrentMovement == AirMovement && mHasDoubleJumped) { mCurrentMovement = AfterDoubleJump; } }
public abstract void Execute(GameObject agent, MovementValues movementValues);
private void JumpVelocity() { bool jumpPushed = JumpInput.WasJustPressed && InputEnabled; bool jumpDown = JumpInput.IsDown && InputEnabled; if (jumpPushed && CurrentMovement.JumpVelocity > 0 && (mIsOnGround || AfterDoubleJump == null || (AfterDoubleJump != null && mHasDoubleJumped == false)) ) { mTimeJumpPushed = CurrentTime; this.YVelocity = CurrentMovement.JumpVelocity; mValuesJumpedWith = CurrentMovement; if (CurrentMovementType == MovementType.Air) { mHasDoubleJumped = true ; } } double secondsSincePush = CurrentTime - mTimeJumpPushed; if (mValuesJumpedWith != null && secondsSincePush < mValuesJumpedWith.JumpApplyLength && (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpInput.IsDown) ) { this.YVelocity = mValuesJumpedWith.JumpVelocity; } if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold && (!JumpInput.IsDown || mHitHead) ) { mValuesJumpedWith = null; } this.YVelocity = Math.Max(-CurrentMovement.MaxFallSpeed, this.YVelocity); }
private void CustomInitialize() { mCurrentMovement = GroundMovement; YAcceleration = this.CurrentMovement.Gravity; }
public void SetMovementValues(MovementValues receivedMovementValues) { movementValues = receivedMovementValues; //some jank to get this working }
private void JumpVelocityActivity() { if (JumpPushed && // If the jump button was pushed CurrentMovement.JumpVelocity > 0 && // the current movement variable has a non-zero jump velocity (mIsOnGround || AfterDoubleJump == null || (AfterDoubleJump != null && mHasDoubleJumped == false)) ) { mTimeJumpPushed = CurrentTime; this.YVelocity = CurrentMovement.JumpVelocity; mValuesJumpedWith = CurrentMovement; if (mCurrentMovement == AirMovement) { mHasDoubleJumped = true ; } } double secondsSincePush = CurrentTime - mTimeJumpPushed; if (mValuesJumpedWith != null && secondsSincePush < mValuesJumpedWith.JumpApplyLength && (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpDown) ) { this.YVelocity = mValuesJumpedWith.JumpVelocity; } if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold && (!JumpDown || mHitHead) ) { mValuesJumpedWith = null; } }