Exemple #1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E) && pickup.carrying != null)
     {
         Liftable liftable = pickup.carrying;
         pickup.PutDown();
         Rigidbody rb = liftable.GetComponent <Rigidbody>();
         rb.AddForce(transform.forward * thrust, ForceMode.Impulse);
         Debug.Log("throw");
     }
 }
Exemple #2
0
    public static void Lift(Physics lifter)
    {
        if (LiftTarget == null || Lifted)
        {
            return;
        }

        Utilities.Instance.SpritePop(LiftTarget.GetComponent <SpriteRenderer>(), Color.white);

        Lifted = true;
        LiftTarget.transform.SetParent(lifter.transform, true);

        lifter.CombinePhysics(LiftTarget.Physics);
    }
Exemple #3
0
    public void FixedUpdate()
    {
        if (LiftState == ForceLiftState.Selecting)
        {
            // If the Hair Trigger is activated, start drawing a selector
            if (ViveInput.GetPress(mHand, ControllerButton.HairTrigger))
            {
                RaycastHit hit;

                // Raycast out from the hand position
                if (Physics.Raycast(transform.position, transform.forward, out hit))
                {
                    // Update the selector to be at the position of the collision
                    if (mLiftSelector)
                    {
                        mLiftSelector.SetActive(true);
                        mLiftSelector.transform.position = hit.point;
                    }

                    // Try to get a liftable from the collider.
                    mCurrentLiftable = hit.collider.GetComponentInParent <Liftable>();
                    Renderer renderer = mLiftSelector.GetComponent <MeshRenderer>();

                    if (mCurrentLiftable)
                    {
                        renderer.material = PositiveLiftMaterial;
                    }
                    else
                    {
                        renderer.material = NegativeLiftMaterial;
                    }
                }
            }
            else
            {
                mLiftSelector.SetActive(false);
            }

            if (ViveInput.GetPressDown(mHand, ControllerButton.FullTrigger) && mCurrentLiftable != null)
            {
                mLiftSelector.SetActive(false);
                LiftState = ForceLiftState.Lifting;

                mCurrentLiftable.Lifted();
            }
        }
        else if (LiftState == ForceLiftState.Lifting)
        {
            if (ViveInput.GetPressDown(mHand, ControllerButton.Trigger))
            {
                // Stop the object.
                Rigidbody liftableRigidbody = mCurrentLiftable.GetComponent <Rigidbody>();
                liftableRigidbody.velocity = Vector3.zero;
            }

            if (ViveInput.GetPress(mHand, ControllerButton.Trigger))
            {
                Rigidbody liftableRigidbody = mCurrentLiftable.GetComponent <Rigidbody>();
                liftableRigidbody.AddForce(LiftForce * (transform.position - mPreviousPosition));
            }
            else
            {
                mAudioSource.Stop();
            }
        }

        mPreviousPosition = transform.position;
    }