Exemple #1
0
        /// <summary>
        /// Removes the arrow from the bow it is in, firing it if the bow is pulled back
        /// </summary>
        public void ReleaseFromBow()
        {
            if (!currentBow)
            {
                return;
            }

            scoreFromHit = 0;

            //get the force at which the arrow should be released
            Vector3 fireForce = currentBow.GetFireForce();

            //Detach from bow
            currentBow.CurrentArrow = null;
            holdingController       = null;
            currentBow = null;

            //unparent from bow
            transform.SetParent(null);

            //set rigidbody back to dynamic
            Rigidbody.isKinematic = false;

            //release the arrow
            Rigidbody.AddForce(fireForce);

            //Arrow can be thrown again when not in bow
            ThrowOnRelease = true;

            //Enable grabbing
            SetGrabbable(true);
        }
Exemple #2
0
        /// <summary>
        /// Equips an arrow to this bow
        /// </summary>
        /// <param name="_arrow">Arrow to put in the bow</param>
        /// <param name="_heldController">Controller holding the arrow, will be used for pulling back string</param>
        public void EquipArrow(Arrow _arrow, InteractGrab _heldController)
        {
            //Set arrow and controller
            CurrentArrow    = _arrow;
            arrowController = _heldController;

            //create a transform for the arrow nocked position, parent it so it moves with the bow
            if (!arrowNockedPosition)
            {
                arrowNockedPosition = new GameObject().transform;
                arrowNockedPosition.SetParent(transform);
            }

            //Set the position of the nocked position to where the controller is
            arrowNockedPosition.SetPositionAndRotation(_heldController.transform.position, transform.rotation);
        }
Exemple #3
0
        /// <summary>
        /// Places the arrow inside a bow, removing free control from the hand holding it
        /// </summary>
        private void AttachToBow(Bow _bow)
        {
            //Get parent controller
            holdingController = transform.parent.GetComponent <VrController>().GetComponent <InteractGrab>();

            //Set parent to bow and go to position
            transform.SetParent(_bow.transform);
            transform.position = _bow.arrowPosition.position;
            transform.rotation = _bow.arrowPosition.rotation;

            //Set kinematic so no longer effected by gravity
            Rigidbody.isKinematic = true;

            //When letting go, do not use controller velocity
            ThrowOnRelease = false;

            //Set in bow
            _bow.EquipArrow(this, holdingController);
            currentBow = _bow;

            //Disable grabbing
            SetGrabbable(false);
        }