Ejemplo n.º 1
0
        private void Ungrab(bool carryMomentum, uint controllerIndex, GameObject target)
        {
            bodyPhysics.TogglePreventSnapToFloor(false);
            bodyPhysics.enableBodyCollisions = true;

            if (carryMomentum)
            {
                Vector3 velocity = Vector3.zero;
                var     device   = VRTK_DeviceFinder.GetControllerByIndex(controllerIndex, false);

                if (device)
                {
                    velocity = -VRTK_DeviceFinder.GetControllerVelocity(device);
                    if (usePlayerScale)
                    {
                        velocity = Vector3.Scale(velocity, playArea.localScale);
                    }
                }

                bodyPhysics.ApplyBodyVelocity(velocity, true, true);
            }

            isClimbing         = false;
            grabbingController = null;
            climbingObject     = null;

            OnPlayerClimbEnded(SetPlayerClimbEvent(controllerIndex, target));
        }
Ejemplo n.º 2
0
        private void Ungrab(bool carryMomentum, uint controllerIndex)
        {
            bodyPhysics.TogglePreventSnapToFloor(false);
            bodyPhysics.enableBodyCollisions = true;

            if (carryMomentum)
            {
                Vector3 velocity = Vector3.zero;
                var     device   = VRTK_DeviceFinder.GetControllerByIndex(controllerIndex, false);

                if (device)
                {
                    velocity = -VRTK_DeviceFinder.GetControllerVelocity(device);
                    if (usePlayerScale)
                    {
                        velocity = Vector3.Scale(velocity, playArea.localScale);
                    }
                }
                Vector3 throwVelocity = Vector3.ClampMagnitude(velocity * throwMultiplier, maxSpeed);
                if (throwVelocity.y <= 1)
                {
                    throwVelocity.y = 1;
                }
                bodyPhysics.ApplyBodyVelocity(throwVelocity * throwMultiplier, true, true);
            }

            isClimbing         = false;
            grabbingController = null;

            OnPlayerClimbEnded(SetPlayerClimbEvent(controllerIndex));
        }
Ejemplo n.º 3
0
        protected virtual void Ungrab(bool carryMomentum, VRTK_ControllerReference controllerReference, GameObject target)
        {
            bodyPhysics.TogglePreventSnapToFloor(false);
            bodyPhysics.enableBodyCollisions = true;

            if (carryMomentum)
            {
                Vector3 velocity = Vector3.zero;

                if (VRTK_ControllerReference.IsValid(controllerReference))
                {
                    velocity = -VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
                    if (usePlayerScale)
                    {
                        velocity = playArea.TransformVector(velocity);
                    }
                    else
                    {
                        velocity = playArea.TransformDirection(velocity);
                    }
                }

                bodyPhysics.ApplyBodyVelocity(velocity, true, true);
            }

            isClimbing         = false;
            grabbingController = null;
            climbingObject     = null;

            OnPlayerClimbEnded(SetPlayerClimbEvent(controllerReference, target));
        }
Ejemplo n.º 4
0
        protected virtual void Ungrab(bool carryMomentum, VRTK_ControllerReference controllerReference, GameObject target)
        {
            if (bodyPhysics == null)
            {
                return;
            }

            isClimbing = false;
            if (positionRewind != null && IsHeadsetColliding())
            {
                positionRewind.RewindPosition();
            }
            if (IsBodyColliding() && !IsHeadsetColliding())
            {
                bodyPhysics.ForceSnapToFloor();
            }

            bodyPhysics.enableBodyCollisions = true;

            if (carryMomentum)
            {
                Vector3 velocity = Vector3.zero;

                if (VRTK_ControllerReference.IsValid(controllerReference))
                {
                    velocity = -VRTK_DeviceFinder.GetControllerVelocity(controllerReference);
                    if (usePlayerScale)
                    {
                        velocity = playArea.TransformVector(velocity);
                    }
                    else
                    {
                        velocity = playArea.TransformDirection(velocity);
                    }
                }

                bodyPhysics.ApplyBodyVelocity(velocity, true, true);
            }

            grabbingController = null;
            climbingObject     = null;

            OnPlayerClimbEnded(SetPlayerClimbEvent(controllerReference, target));
        }
Ejemplo n.º 5
0
        protected virtual void CheckForJump()
        {
            if (leftButtonReleased && rightButtonReleased && !bodyPhysics.IsFalling())
            {
                Vector3 leftDir      = leftStartAimPosition - leftReleasePosition;
                Vector3 rightDir     = rightStartAimPosition - rightReleasePosition;
                Vector3 localJumpDir = leftDir + rightDir;
                Vector3 worldJumpDir = playArea.transform.TransformVector(localJumpDir);
                Vector3 jumpVector   = worldJumpDir * velocityMultiplier;

                if (jumpVector.magnitude > velocityMax)
                {
                    jumpVector = jumpVector.normalized * velocityMax;
                }

                bodyPhysics.ApplyBodyVelocity(jumpVector, true, true);

                UnAim();

                OnSlingshotJumped();
            }
        }