IPlayerState IPlayerState.Update(PlayerMovementRB player)
        {
            if (player.controlState == ControlState.CONTROLLABLE)
            {
                if (player.directionVector.sqrMagnitude != 0)
                {
                    return player.statePool.GetState("MOVING");
                }
                else if (Input.GetButtonDown(player.jumpButton))
                {
                    return player.statePool.GetState("JUMPING");
                }
                else if (Input.GetButtonDown(player.interactButton))
                {
                    player.Interact();
                }
                else if (Input.GetButtonDown(player.crouchButton))
                {
                    return player.statePool.GetState("CROUCHING");
                }
            }

            if (!player.grounded)
            {
                return player.statePool.GetState("FALLING");
            }

            // TODO: if( crouch is pressed) { return new PlayerStateCrouching(); }
            return this;
        }
        IPlayerState IPlayerState.Update(PlayerMovementRB player)
        {
            // Set animator speed and then if not moving go to Idle state
            player.anim.SetFloat("Speed", player.currentSpeed);

            if (player.controlState == ControlState.CONTROLLABLE)
            {
                if (player.directionVector.sqrMagnitude == 0)
                {
                    return player.statePool.GetState("CROUCHING");
                }
                if (Input.GetButtonUp(player.crouchButton))
                {
                    if (player.directionVector.sqrMagnitude == 0)
                    {
                        return player.statePool.GetState("CROUCHING");
                    }
                    else
                    {
                        return player.statePool.GetState("MOVING");
                    }
                }
            }
            else
            {
                return player.statePool.GetState("CROUCHING");
            }

            return this;
        }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     player.anim.SetBool("Falling", true);
     player.SetCrouching(true);
     // Minimum friction so you don't stick to walls while falling
     player.col.material.dynamicFriction = 0f;
 }
        IPlayerState IPlayerState.Update(PlayerMovementRB player)
        {
            // Check if the player jumped BEFORE we check if they aren't grounded
            // so if both happen in the same frame they can still jump
            if (Input.GetButtonDown(player.jumpButton))
            {
                return player.statePool.GetState("JUMPING");
            }
            else if (!player.grounded)
            {
                return player.statePool.GetState("FALLING");
            }
            else if (Input.GetButtonDown(player.interactButton))
            {
                player.Interact();
            }
            else if (Input.GetButtonDown(player.crouchButton))
            {
                return player.statePool.GetState("CRAWLING");
            }

            // Set animator speed and then if not moving go to Idle state
            player.anim.SetFloat("Speed", player.currentSpeed);
            if (player.directionVector.sqrMagnitude == 0)
            {
                return player.statePool.GetState("IDLE");
            }
            return this;
        }
 IPlayerState IPlayerState.ProcessMovement(PlayerMovementRB player)
 {
     if (player.controlState == ControlState.CONTROLLABLE)
     {
         player.RotateToFace();
     }
     return this;
 }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     // TODO manually set the player's Y-position
     //player.rb.useGravity = false;
     //jumpTimer.StartTiming();
     if (player.controlState == ControlState.CONTROLLABLE)
     {
         player.SetCrouching(false);
         player.anim.SetBool("Falling", true);
         player.col.material.dynamicFriction = 0f;
         player.rb.AddForce(jumpForce, ForceMode.VelocityChange);
     }
 }
        IPlayerState IPlayerState.Update(PlayerMovementRB player)
        {
            if (player.grounded)
            {
                player.anim.SetBool("Falling", false);

                // Reset friction before leaving this state
                player.col.material.dynamicFriction = 1f;

                return player.statePool.GetState("IDLE");
            }
            return this;
        }
        IPlayerState IPlayerState.ProcessMovement(PlayerMovementRB player)
        {
            if (player.controlState == ControlState.CONTROLLABLE)
            {
                // Move the player
                Vector3 velocityChange = player.directionVector - player.rb.velocity;
                velocityChange.x = Mathf.Clamp(velocityChange.x, -player.maxVelocityChange, player.maxVelocityChange);
                velocityChange.z = Mathf.Clamp(velocityChange.z, -player.maxVelocityChange, player.maxVelocityChange);
                velocityChange.y = 0;

                player.rb.AddForce(velocityChange, ForceMode.VelocityChange);
            }
            player.RotateToFace();
            return this;
        }
 IPlayerState IPlayerState.Update(PlayerMovementRB player)
 {
     if (player.rb.velocity.y < 0)
     {
         return player.statePool.GetState("FALLING");
     }
     else if (player.grounded)
     {
         return player.statePool.GetState("IDLE");
     }
     else if(player.carryState == CarryState.CARRYING && Input.GetButtonDown(player.interactButton))
     {
         player.Interact();
     }
     return this;
 }
        IPlayerState IPlayerState.Update(PlayerMovementRB player)
        {
            if (player.controlState == ControlState.CONTROLLABLE)
            {
                if (!Input.GetButton(player.crouchButton))
                {
                    return player.statePool.GetState("IDLE");
                }
                if (player.directionVector.sqrMagnitude != 0)
                {
                    return player.statePool.GetState("CRAWLING");
                }
            }

            if (!player.grounded)
            {
                return player.statePool.GetState("FALLING");
            }
            return this;
        }
Beispiel #11
0
        // Use this for initialization
        void Start()
        {
            PlayerStatus.playerCount++;
            controlState = ControlState.NOT_CONTROLLABLE;
            movement = GetComponent<PlayerMovementRB>();
            audioScript = GetComponent<PlayerAudio>();

            if (playerNumber <= 0 || playerNumber > 4)
            {
                Debug.LogError(this + ": playerNumber should be 1 to 4, was: " + playerNumber);
            }

            health = startingHealth;
            movement.SetPlayer(playerNumber);
        }
 IPlayerState IPlayerState.ProcessJump(PlayerMovementRB player)
 {
     return this;
 }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     player.SetCrouching(true);
 }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     player.anim.SetFloat("Speed", 0f);
     player.SetCrouching(true);
 }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     Error();
 }
 IPlayerState IPlayerState.Update(PlayerMovementRB player)
 {
     return this;
 }
 IPlayerState IPlayerState.ProcessJump(PlayerMovementRB player)
 {
     // Not actually using this at the moment
     // TODO: do it by manually setting Y-height, but need to figure out how to also maintain X/Z momentum
     return this;
 }
 void IPlayerState.EnterState(PlayerMovementRB player)
 {
     player.anim.SetFloat("Speed", player.currentSpeed);
     player.SetCrouching(false);
 }