Пример #1
0
        public virtual void Move()
        {
            if (THInput.GetButton("Forward"))
            {
                Forward();
            }
            if (THInput.GetButton("Backwards"))
            {
                Back();
            }

            if (THInput.GetButton("Left"))
            {
                Left();
            }
            if (THInput.GetButton("Right"))
            {
                Right();
            }

            JumpBounce();
            if (THInput.GetButton("Jump") && IsGrounded())
            {
                Jump();
            }
        }
Пример #2
0
        /// <summary>
        /// Moves the player
        /// </summary>
        void MovePlayer()
        {
            //Calculate the speed we want to achive
            Vector3 targetVelocity = new Vector3(THInput.GetAxis("Horizontal"), 0, THInput.GetAxis("Vertical"));

            targetVelocity  = transform.TransformDirection(targetVelocity);
            targetVelocity *= speed;

            //Apply a force to reach the target speed
            Vector3 velocity       = myRigidBody.velocity;
            Vector3 velocityChange = (targetVelocity - velocity);

            //Clamping the velocity so that the player does not infinatly accelerate
            velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocity, maxVelocity);
            velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocity, maxVelocity);
            velocityChange.y = 0;

            //Adds the force to the player so they move in the correct direction
            myRigidBody.AddForce(velocityChange, ForceMode.Impulse);

            //Jumping
            if (canJump && THInput.GetButton("Jump"))
            {
                canJump = false;
                myRigidBody.velocity = new Vector3(velocity.x, VerticalJumpSpeed(), velocity.z);
            }
        }
Пример #3
0
 private void JumpBounce()
 {
     if (playerRigidbody.velocity.y < 0)
     {
         playerRigidbody.velocity += Vector3.up * Gravity() * (fallMultiplier - 1) * Time.fixedDeltaTime;
     }
     else if (playerRigidbody.velocity.y > 0 && !THInput.GetButton("Jump"))
     {
         playerRigidbody.velocity += Vector3.up * Gravity() * (lowJumpMultiplier - 1) * Time.fixedDeltaTime;
     }
 }
Пример #4
0
        /// <summary>
        /// Goves the inventory update ticks
        /// </summary>
        protected void Update()
        {
            UpdateBase();

            //* checks if the inventory should be opened/closed
            if ((thisInventoryOpen || !playerInventory.activeInHierarchy) && !THInput.chestOpen && THInput.GetButtonDown("Player Inventory"))
            {
                if (THInput.blockInventoryJustClosed)
                {
                    THInput.blockInventoryJustClosed = false;
                    return;
                }
                else
                {
                    OpenPlayerInventory();
                }
            }

            //* dont pickup items if the inventory is open
            if (THInput.isAnotherInventoryOpen)
            {
                return;
            }

            //* checks if somethig should be picked up and put into the inventory
            RaycastHit[] hit = Physics.SphereCastAll(transform.position, 1f, transform.forward);

            for (int i = hit.Length - 1; i >= 0; i--)
            {
                if (hit[i].collider.GetComponent <ItemGameObject>())
                {
                    PickupItem(hit[i].collider.GetComponent <ItemGameObject>());
                }
            }
        }