public void OnEnteredState(PlayerParams playerParams) { beforeJumpVelocity = playerParams.rigidBody.velocity; wallRunTime = playerParams.wallRunForceAppliedTime; cameraTransform = playerParams.player.mouseLook.cameraTransform; }
public void FixedUpdateState(PlayerParams playerParams) { if (playerParams.isGrounded) { Move(playerParams); } }
private void HandleWallSliding(PlayerParams playerParams, RaycastHit wallHit) { // If is sliding down if (Vector3.Dot(playerParams.rigidBody.velocity, Vector3.up) < 0) { playerParams.rigidBody.AddForce(new Vector3(0, playerParams.gravityCounterForce, 0), ForceMode.Force); } }
private void Move(PlayerParams playerParams) { if (playerParams.moveDirection != Vector3.zero) { playerParams.player.StickToGround(); } playerParams.player.Move(playerParams.walkSpeed); }
// Called in Fixed Update public void RotatePlayer(PlayerParams playerParams) { float horizontal = Input.GetAxis(horizontalAxisName); Vector3 direction = Vector3.up * horizontal * (mouseSentivity * Time.fixedDeltaTime); playerParams.rigidBody.rotation *= Quaternion.Euler(direction); }
public void FixedUpdateState(PlayerParams playerParams) { // if toching wall, else falling state or onground if (canWallRun) { WallRun(playerParams); } HandleWallSliding(playerParams, wallHit); HandleWallJumping(playerParams); }
private void Move(PlayerParams playerParams) { Vector3 targetDirection = playerParams.moveDirection; if (!playerParams.IsTouchingAWall() && targetDirection != Vector3.zero && !playerParams.isColliding) { Vector3 velocity = playerParams.rigidBody.velocity; Vector3 targetVelocity = beforeJumpVelocity + (targetDirection * playerParams.fallingMoveSpeed); // playerParams.player.Move(targetVelocity); playerParams.rigidBody.AddForce(targetDirection * playerParams.fallingMoveSpeed, ForceMode.Force); } }
public void UpdateState(PlayerParams playerParams) { if (playerParams.IsTouchingAWall()) { RaycastHit wallHit = playerParams.player.GetClosestWall(); // If the player is not just toching the wall but the direction is going toward the wall. if (playerParams.player.IsMovingInDirectionOfTheWall()) { playerParams.player.SetState(new PlayerOnWallState(wallHit, canWallRun)); } } if (playerParams.isGrounded) { playerParams.player.SetState(new PlayerOnGroundState()); } }
private void HandleWallJumping(PlayerParams playerParams) { if (jump && !alreadyJumped) { jump = false; alreadyJumped = true; Vector3 perpandicularVec = playerParams.player.GetVectorParalelToWall(wallHit); Vector3 axis = playerParams.leftWallHit ? perpandicularVec : -perpandicularVec; Vector3 rotatedVector = Quaternion.AngleAxis(playerParams.wallJumpAngle, axis) * wallHit.normal; rotatedVector *= playerParams.wallJumpForce; Vector3 direction = rotatedVector + playerParams.rigidBody.velocity; direction = Vector3.ClampMagnitude(direction, playerParams.wallRunSpeed); playerParams.player.Jump(direction); } }
public void UpdateState(PlayerParams playerParams) { if (!jump) { jump = GameManager.InputHandler.haveJumpInputBeenPressed; } wallRunTime -= Time.deltaTime; if (wallRunTime < 0) { canWallRun = false; } if (!playerParams.IsTouchingAWall() || playerParams.isGrounded) { playerParams.player.SetState(new PlayerFallingState(false)); } }
public void UpdateState(PlayerParams playerParams) { if (playerParams.isGrounded) { if (GameManager.InputHandler.haveJumpInputBeenPressed) { playerParams.player.Jump(); } else if (GameManager.InputHandler.isRunButtonBeingPressed) { playerParams.player.SetState(new PlayerOnGroundRunningState()); } } else { playerParams.player.SetState(new PlayerFallingState()); } }
private void WallRun(PlayerParams playerParams) { RaycastHit wallHit = playerParams.player.GetClosestWall(); if (playerParams.player.IsMovingInDirectionOfTheWall()) { // GetVectorParalelToWall Vector3 targetDirection = playerParams.player.GetVectorParalelToWall(wallHit); // Rotate the vector paralelle to the wall upward at wallRunAngle // The normal direction should always be from left to right else the rotation will be downward Vector3 axis = playerParams.leftWallHit ? wallHit.normal : -wallHit.normal; float angle = Vector3.Dot(cameraTransform.forward, Vector3.up) > 0 ? -GetRunAngle(playerParams, targetDirection) : 0; Vector3 rotatedTargetDirection = Quaternion.AngleAxis(angle, axis) * targetDirection; Vector3 targetVelocity = (rotatedTargetDirection * playerParams.wallRunSpeed); // TODO Vector3 currentVel = playerParams.rigidBody.velocity; currentVel.Normalize(); targetVelocity += currentVel; playerParams.rigidBody.velocity = targetVelocity; } }
public void OnExitState(PlayerParams playerParams) { }
private float GetRunAngle(PlayerParams playerParams, Vector3 perpandicularVector) { return(Vector3.Angle(cameraTransform.forward, perpandicularVector)); }
// States used: FallingState, PlayerOnGroundRunningState public void OnEnteredState(PlayerParams playerParams) { }
public void OnEnteredState(PlayerParams playerParams) { rigid = playerParams.rigidBody; }
public void FixedUpdateState(PlayerParams playerParams) { }
public void OnEnteredState(PlayerParams playerParams) { beforeJumpVelocity = playerParams.rigidBody.velocity; }