예제 #1
0
        public void OnEnteredState(PlayerParams playerParams)
        {
            beforeJumpVelocity = playerParams.rigidBody.velocity;
            wallRunTime        = playerParams.wallRunForceAppliedTime;

            cameraTransform = playerParams.player.mouseLook.cameraTransform;
        }
예제 #2
0
 public void FixedUpdateState(PlayerParams playerParams)
 {
     if (playerParams.isGrounded)
     {
         Move(playerParams);
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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);
        }
예제 #6
0
        public void FixedUpdateState(PlayerParams playerParams)
        {
            // if toching wall, else falling state or onground
            if (canWallRun)
            {
                WallRun(playerParams);
            }

            HandleWallSliding(playerParams, wallHit);
            HandleWallJumping(playerParams);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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());
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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));
            }
        }
예제 #11
0
 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());
     }
 }
예제 #12
0
        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;
            }
        }
예제 #13
0
 public void OnExitState(PlayerParams playerParams)
 {
 }
예제 #14
0
 private float GetRunAngle(PlayerParams playerParams, Vector3 perpandicularVector)
 {
     return(Vector3.Angle(cameraTransform.forward, perpandicularVector));
 }
        // States used: FallingState, PlayerOnGroundRunningState


        public void OnEnteredState(PlayerParams playerParams)
        {
        }
예제 #16
0
 public void OnEnteredState(PlayerParams playerParams)
 {
     rigid = playerParams.rigidBody;
 }
 public void FixedUpdateState(PlayerParams playerParams)
 {
 }
예제 #18
0
 public void OnEnteredState(PlayerParams playerParams)
 {
     beforeJumpVelocity = playerParams.rigidBody.velocity;
 }