示例#1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other == Player.instance.headCollider)
        {
            Debug.Log(other);
            Player.instance.transform.position = spawnTransform.position;
            Player.instance.transform.rotation = spawnTransform.rotation;

            return;
        }

        // Test for force grabbable objects
        ForceGrabbable forceGrabbable = other.GetComponent <ForceGrabbable>();

        if (forceGrabbable == null)
        {
            forceGrabbable = other.GetComponentInParent <ForceGrabbable>();
        }

        if (forceGrabbable != null)
        {
            forceGrabbable.ReturnToOriginalTransform();
            return;
        }
    }
示例#2
0
    private void ReleaseGrip()
    {
        // Let go of the force grab, if one's happening
        if (forceGrabbableTarget != null)
        {
            //forceGrabbableTarget.OnRelease(this);
            forceGrabbableTarget = null;
        }

        DestroyCurrentGrapplePoint();
    }
示例#3
0
    // --------------------------------------------------------------------------------
    // New Force Grab
    // --------------------------------------------------------------------------------
    // x Force grab
    // TODO: Relative pull/push
    //  - Absolute mode:
    //      - Force grab position is lerp'd to a point x meters from the blaster hand
    //  - Relative mode:
    //      - Trigger button activates pull/push mode
    //      - Horizontal/vertical motion is the same
    //      - Forward/back is relative to blaster's position when relative mode was entered
    //
    // TODO: Throw velocity to match Throwable
    public void RegisterForceGrabbable(GameObject target)
    {
        forceGrabBlasterStartPosition = blaster.spawnTransform.position;
        relativePushPull = false;

        forceGrabbableTarget = target.GetComponentInParent <ForceGrabbable>();
        if (forceGrabbableTarget != null)
        {
            currentForceGrabDistance = initialForceGrabDistance;
            //forceGrabbableTarget.OnGrab(this);
        }
    }
示例#4
0
    public void OnGrappleProjectileCollision(Collider other)
    {
        // Test if we can actually collide with this object
        if (((1 << other.gameObject.layer) & grabbableLayers) == 0)
        {
            isGrappleProjectileDeployed = false;
            StopDrawingGrappleLighting();
            Destroy(grabPoint.gameObject);
            return;
        }


        // Test if we should grapple to the target, or force grab the target
        forceGrabbableTarget = other.GetComponent <ForceGrabbable>();
        if (forceGrabbableTarget == null)
        {
            // -- Grapple
            grabPoint.velocity         = Vector3.zero;
            grabPoint.isKinematic      = true;
            grabPoint.transform.parent = other.gameObject.transform;

            OnGrappleStart();
        }
        else
        {
            // -- Force grab
            ForceGrabbableLimb limb = forceGrabbableTarget as ForceGrabbableLimb;
            if (limb)
            {
                // Configure the character joint to stick to the target
                limb.ConfigureDelegateForceGrabTarget(grappleProjectile);

                limb.OnGrab(this);
            }
            else
            {
                // Stick to the target
                grabPoint.velocity         = Vector3.zero;
                grabPoint.isKinematic      = true;
                grabPoint.transform.parent = other.gameObject.transform;
            }

            OnForceGrabStart();
        }
    }
    private void GrabObject(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState)
    {
        if (!isSelected)
        {
            return;
        }

        if (isGrabbing)
        {
            if (!newState)
            {
                // -- Throw the object
                isGrabbing = false;
                currentTarget.OnRelease();

                // -- Add force to the projectile
                Vector3 handDelta = Vector3.zero;

                // Iterate over each hand position, and calculate the delta. Add them up, and find the average
                foreach (Vector3 delta in handDeltaHistory)
                {
                    handDelta += delta;
                }

                currentTarget.rb.AddForce(handDelta / handPositionHistoryCount * throwForceMultiplier, ForceMode.VelocityChange);
            }
        }
        else
        {
            if (newState)
            {
                // -- Attempt to pick up an object
                if (Physics.Raycast(castingHand.transform.position, castingHand.transform.forward.normalized, out RaycastHit hit, raycastDistance, layermask))
                {
                    // -- Hit: Raycast to the collision point
                    lineRenderer.SetPosition(0, castingHand.transform.position);
                    lineRenderer.SetPosition(1, hit.point);
                    lineRendererAnimator.SetTrigger("fire");

                    // -- This object we collided with can be grabbed
                    // Check both the immediate object, and its parent.
                    //  We can have gameobjects with child colliders
                    ForceGrabbable forceGrabbable = hit.collider.GetComponent <ForceGrabbable>();
                    if (forceGrabbable == null)
                    {
                        forceGrabbable = hit.collider.GetComponentInParent <ForceGrabbable>();
                    }

                    if (forceGrabbable != null)
                    {
                        // Can't grab slotted targets
                        if (forceGrabbable.isSlotted)
                        {
                            return;
                        }

                        hoverDistance = initialHoverDistance;

                        isGrabbing    = true;
                        currentTarget = forceGrabbable;
                        currentTarget.OnGrab();
                    }
                }
                else
                {
                    // -- Missed: Raycast into air
                    lineRenderer.SetPosition(0, castingHand.transform.position);
                    lineRenderer.SetPosition(1, castingHand.transform.position + castingHand.transform.forward * raycastDistance);
                    lineRendererAnimator.SetTrigger("fire");
                }
            }
        }