Exemple #1
0
        public Vector2 Update(Vector2 velocity)
        {
            MovementProperties movementProperties = m_PlayerRef.MovementProperties;

            float deltaX = velocity.x;
            float deltaY = velocity.y - movementProperties.Gravity;

            //Potentional double jump

            //Moving horizontally
            float horizValue = InputManager.Instance.GetAxis("HorizontalAxis_" + m_PlayerRef.PlayerID);

            deltaX += horizValue * movementProperties.Acceleration;

            if (horizValue == 0.0f && deltaX != 0.0f)
            {
                float sign = Mathf.Sign(m_PlayerRef.Velocity.x);
                deltaX -= movementProperties.Friction * sign;

                if (sign != Mathf.Sign(deltaX))
                {
                    deltaX = 0.0f;
                }
            }

            if (m_PlayerRef.CharacterController.IsGrounded)
            {
                m_PlayerRef.SetState(Player.PlayerState.Walk);
            }

            //Shoot
            m_PlayerRef.SetFiring((InputManager.Instance.GetButton("Fire_" + m_PlayerRef.PlayerID)));

            return(new Vector2(deltaX, deltaY));
        }
Exemple #2
0
        public Vector2 Update(Vector2 velocity)
        {
            MovementProperties movementProperties = m_PlayerRef.MovementProperties;

            float deltaX = velocity.x;
            float deltaY = velocity.y - movementProperties.Gravity;

            //Moving horizontally
            float horizValue = InputManager.Instance.GetAxis("HorizontalAxis_" + m_PlayerRef.PlayerID);

            deltaX += horizValue * movementProperties.Acceleration;

            if (horizValue == 0.0f && deltaX != 0.0f)
            {
                float sign = Mathf.Sign(m_PlayerRef.Velocity.x);
                deltaX -= movementProperties.Friction * sign;

                if (sign != Mathf.Sign(deltaX))
                {
                    deltaX = 0.0f;
                }
            }

            //Change to jump state
            if (m_PlayerRef.CharacterController.IsGrounded)
            {
                if (InputManager.Instance.GetButton("Jump_" + m_PlayerRef.PlayerID))
                {
                    //Change to the jump state
                    m_PlayerRef.SetState(Player.PlayerState.Jump);
                }
                else
                {
                    //Stick better to the ground
                    deltaY -= movementProperties.Gravity * 10.0f;
                }
            }
            else
            {
                //Change to the fall state
                deltaY = 0.0f;
                m_PlayerRef.SetState(Player.PlayerState.Fall);
            }

            //Shoot
            m_PlayerRef.SetFiring((InputManager.Instance.GetButton("Fire_" + m_PlayerRef.PlayerID)));

            return(new Vector2(deltaX, deltaY));
        }
Exemple #3
0
        public Vector2 Update(Vector2 velocity)
        {
            MovementProperties movementProperties = m_PlayerRef.MovementProperties;

            float deltaX = velocity.x;
            float deltaY = velocity.y - movementProperties.Gravity;

            //Moving horizontally
            float horizValue = InputManager.Instance.GetAxis("HorizontalAxis_" + m_PlayerRef.PlayerID);

            deltaX += horizValue * movementProperties.Acceleration;

            if (horizValue == 0.0f && deltaX != 0.0f)
            {
                float sign = Mathf.Sign(m_PlayerRef.Velocity.x);
                deltaX -= movementProperties.Friction * sign;

                if (sign != Mathf.Sign(deltaX))
                {
                    deltaX = 0.0f;
                }
            }

            if (InputManager.Instance.GetButton("JumpPressed_" + m_PlayerRef.PlayerID))
            {
                float factor = 1.0f - (m_CurrentJumpTime / movementProperties.MaxJumpTime);
                deltaY += (movementProperties.JumpAcceleration * (factor * factor));

                m_CurrentJumpTime += Time.deltaTime;
                if (m_CurrentJumpTime > movementProperties.MaxJumpTime)
                {
                    m_PlayerRef.SetState(Player.PlayerState.Fall);
                }
            }
            else
            {
                m_PlayerRef.SetState(Player.PlayerState.Fall);
            }

            //Shoot
            m_PlayerRef.SetFiring((InputManager.Instance.GetButton("Fire_" + m_PlayerRef.PlayerID)));

            return(new Vector2(deltaX, deltaY));
        }