Exemple #1
0
    void grabObject(GameObject objectToGrab)
    {
        var device = SteamVR_Controller.Input((int)trackedObj.index);

        Grabbable grabbedObject = objectToGrab.GetComponent <Grabbable>();

        if (grabbedObject)
        {
            if (grabbedObject.isGrabbable)
            {
                if (joint == null && device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
                {
                    attachObject(objectToGrab);
                    grabbedObject.GrabberIndex = (int)trackedObj.index;
                }
                if (!joint)
                {
                    device.TriggerHapticPulse(800);
                }

                if (grabbedObject.GetComponent <Smartphone> ())
                {
                    trackSmartphone(grabbedObject.GetComponent <Smartphone> ());
                }
            }
        }
    }
Exemple #2
0
    void Grab(Grabbable target, Vector3 point)
    {
        grabbing = true;

        HoldingHeavy = false;

        if (target.Heavy)
        {
            HoldingHeavy = true;

            var spring = gameObject.AddComponent <SpringJoint>();
            spring.autoConfigureConnectedAnchor = false;
            spring.connectedBody   = target.GetComponent <Rigidbody>();
            spring.anchor          = Vector3.forward * HoldDistance + Vector3.up * HoldElevation;
            spring.connectedAnchor = target.transform.InverseTransformPoint(point);
            spring.spring          = 500;
            spring.damper          = 100;

            joint = spring;
        }
        else
        {
            var fixedJoint = gameObject.AddComponent <FixedJoint>();
            fixedJoint.autoConfigureConnectedAnchor = false;
            fixedJoint.connectedBody   = target.GetComponent <Rigidbody>();
            fixedJoint.anchor          = Vector3.forward * HoldDistance + Vector3.up * HoldElevation;
            fixedJoint.connectedAnchor = target.transform.InverseTransformPoint(point);

            joint = fixedJoint;
        }
    }
Exemple #3
0
    void grab(Grabbable thing)
    {
        calculateNearestGravity();
        if (thing == null)
        {
            if (heldObject != null)
            {
                ungrab();
            }
        }
        else
        {
            heldObject = thing;

            heldObjectAvatar = new GameObject("_HeldBodyAvatar");
            heldObjectAvatar.transform.parent     = Camera.main.transform;
            heldObjectAvatar.transform.position   = heldObject.transform.position;
            heldObjectAvatar.transform.rotation   = heldObject.transform.rotation;
            heldObjectAvatar.transform.localScale = heldObject.transform.localScale;
            heldObjectAvatar.AddComponent <MeshFilter> ().sharedMesh        = heldObject.gameObject.GetComponent <MeshFilter> ().sharedMesh;
            heldObjectAvatar.AddComponent <MeshRenderer> ().sharedMaterials = heldObject.gameObject.GetComponent <Renderer> ().sharedMaterials;

            heldObject.grab(heldObjectAvatar.GetComponent <Renderer> ());
            heldObject.transform.position = pivot.transform.position;
            oldHeldBodyAngularDrag        = heldObject.GetComponent <Rigidbody> ().angularDrag;
            heldObject.GetComponent <Rigidbody> ().angularDrag = 1;
            heldObject.GetComponent <Renderer> ().enabled      = false;

            Physics.IgnoreCollision(heldObject.GetComponent <Collider> (), GetComponent <Collider> (), true);
        }
    }
Exemple #4
0
    void MoveToTheBottle()
    {
        Debug.Log("Move");
        item.transform.SetParent(transform, true);
        iTween.MoveTo(item.gameObject, iTween.Hash("position", prepareToReleasePos.localPosition, "time", prepareToSpinTime, "islocal", true, "easetype", iTween.EaseType.easeInOutCirc, "oncomplete", nameof(PrepareAnimCompleted), "oncompletetarget", gameObject));
        iTween.RotateTo(item.gameObject, iTween.Hash("rotation", Vector3.zero, "time", prepareToSpinTime, "easetype", iTween.EaseType.linear, "islocal", true));

        item.GetComponent <Rigidbody>().isKinematic      = true;
        item.GetComponentInChildren <Collider>().enabled = false;
        item.GetComponent <Grabbable>().enabled          = false;
        ownGrabbable.enabled = false;
    }
Exemple #5
0
 private void ReleaseGrabbedObject()
 {
     if (grabbedObject != null)
     {
         grabbedObject.Release();
         Vector3 repelForce = transform.forward * releaseForce;
         grabbedObject.GetComponent <Rigidbody>().AddForce(repelForce);
         grabbedObject.GetComponent <MergableObject>().OnSizeChanged -= OnHeldSizeChange;
         grabbedObject = null;
         beam.Mode     = PlayerBeam.BeamMode.NEUTRAL;
     }
 }
        public void Pickup()
        {
            currentGrabbable = GetNearestGrabbable();

            if (!currentGrabbable)
            {
                return;
            }
            if (currentGrabbable.ActiveController)
            {
                currentGrabbable.ActiveController.Drop();
            }

            if (currentGrabbable.IsEquippable)
            {
                var poseTransform = pose.transform;
                currentGrabbable.transform.position = poseTransform.position;
                currentGrabbable.transform.rotation = poseTransform.rotation * Quaternion.Euler(currentGrabbable.EquippableOffset);
            }

            currentGrabbable.OnPickup();
            Rigidbody targetBody = currentGrabbable.GetComponent <Rigidbody>();

            joint.connectedBody = targetBody;

            currentGrabbable.ActiveController = this;
        }
    public void Ungrab()
    {
        if (joint != null)
        {
            joint.connectedBody = null;
        }

        if (grabbedObject != null)
        {
            grabbedObject.OnEndGrab?.Invoke(gameObject);
            grabbedObject.rb.isKinematic = false;

            IRagdoll ragdoll = grabbedObject.GetComponent <IRagdoll> ();
            if (ragdoll != null)
            {
                ragdoll.GetRagdoll().transform.parent = null;
            }
            else
            {
                grabbedObject.transform.parent = null;
            }

            grabbedObject = null;
        }
    }
Exemple #8
0
    void TryGrab()
    {
        int resultsCount
            = Physics2D.OverlapCircleNonAlloc(this.transform.position, this.GrabRadius, _grabResults, GrabbableItemMask);

        for (int i = 0; i < resultsCount; i++)
        {
            Grabbable p = _grabResults[i].GetComponent <Grabbable>();
            if (p == null || p.gameObject == this.gameObject)
            {
                continue;
            }
            if (p.IsHeld == false)
            {
                RatPlayer player = p.GetComponent <RatPlayer>();
                if (player != null && player.Dead == true)
                {
                    continue;
                }
                p.Grab(this);
                this._heldItem = p;
                SetState(State.Holding);
                //Debug.Log("Grab");
                break;
            }
        }
    }
Exemple #9
0
    void throwHeldObject()
    {
        Grabbable thing = heldObject;

        ungrab();
        thing.GetComponent <Rigidbody> ().AddForce(Camera.main.transform.forward * 10, ForceMode.Impulse);
    }
Exemple #10
0
    void SnapOnBegining()
    {
        if (snappedItem == null)
        {
            return;
        }

        snappedItem.GetComponent <Rigidbody>().isKinematic      = true;
        snappedItem.GetComponentInChildren <Collider>().enabled = false;
        snappedItem.GetComponent <Grabbable>().enabled          = false;
        snappedItem.transform.SetParent(transform);
        snappedItem.transform.localPosition = Vector3.zero;

        iteamReadyToSnap = snappedItem;
        snapState        = SnapState.Snapped;
        Array.ForEach(snapBegining, s => s.Init(iteamReadyToSnap));
    }
    public override void Interact(GameObject caller)
    {
        Vector3   pos = this.transform.Find("drop").transform.position;
        Grabbable go  = Instantiate(ObjectToSpawn);

        go.transform.position = pos;
        go.GetComponent <Rigidbody>().isKinematic = true;
    }
Exemple #12
0
    //	Grabs a grabbable object that is within range.
    public void Grab()
    {
        // If there is a grabbable object available
        if (grabbableObject != null && objectInHand == false)
        {
            // Disable the grabbed object's rigidbody
            grabbableObject.GetComponent <Rigidbody> ().isKinematic      = true;
            grabbableObject.GetComponent <Rigidbody> ().detectCollisions = false;

            grabbedObjectTf = grabbableObject.GetComponent <Transform> ();

            // Move the Grabbable object to the player's hand
            grabbedObjectTf.position = handTf.position;
            grabbedObjectTf.parent   = handTf;
            objectInHand             = true; // Object is now in the player's hand
        }
    }
Exemple #13
0
    void OnThisWasReleased(Grabbable grabbable)
    {
        var panel = grabbable.GetComponent <Interactor>()?.GetInteractorTargetUnderneathMe() as PanelSystem;

        if (panel != null)
        {
            ObjectManager.Instance.GameManager.AttemptedWireSlotting(this, panel);
        }
    }
Exemple #14
0
    private void Grab(Grabbable grabbable)
    {
        _currentGrabbable = grabbable;

        _grabTime = Time.timeSinceLevelLoad;

        _currentGrabbable.Rigidbody.useGravity       = false;
        _currentGrabbable.OnGrabbableCollisionEnter += OnGrabbableCollisionEnter;
        grabbable.GetComponent <MonsterController>().Grab();
    }
Exemple #15
0
    public void GrabObject(Grabbable grabbableScript)
    {
        if (!(m_GrabbableScript == null && grabbableScript != null))
        {
            return;
        }

        if (_grabDisabledTime > 0)
        {
            return;
        }

        ReleaseObject(0);

        if (m_SoundManager)
        {
            m_SoundManager.PlayGrab();
        }

        m_GrabbableScript = grabbableScript;
        m_GrabbableScript.ReleaseSelf(1);
        m_GrabbableScript.SetGrabber(this);
        if (m_GrabAnchor != null)
        {
            Vector3 vAnchorOffset = transform.position - m_GrabAnchor.position;
            transform.position = transform.position + vAnchorOffset * 0.5f;

            grabbableScript.transform.position = m_GrabAnchor.position;
        }
        var grabbedRigidbody2D = grabbableScript.GetComponent <Rigidbody2D>();

        grabbedRigidbody2D.bodyType = RigidbodyType2D.Dynamic;
        var grabbedCollider = grabbableScript.GetComponent <Collider2D>();

        grabbedCollider.isTrigger         = !m_bIsPlayer;
        m_ConnectingJoint2D               = gameObject.AddComponent <FixedJoint2D>();
        m_ConnectingJoint2D.connectedBody = grabbedRigidbody2D;
        if (!m_bIsPlayer)
        {
            SendMessage("OnGrabObject", grabbableScript);
        }
    }
Exemple #16
0
    public bool ShouldSnap(Grabbable subject)
    {
        Group subjectSnapGroup = subject.GetComponent <Group>();

        if (!subjectSnapGroup)
        {
            return(false);
        }

        return(subjectSnapGroup.IsContaingAnyElement(snapToObjects));
    }
Exemple #17
0
    private void OnReturn()
    {
        while (grabbedItens.Count > 0)
        {
            Grabbable item = grabbedItens[0];
            Release(item);

            PoolableObject poolableItem = item.GetComponent <PoolableObject>();
            poolableItem.ReturnToPool();
        }
    }
Exemple #18
0
    void UpdateHeldItemLayer(int sortingOrder)
    {
        if (heldItem == null)
        {
            som.OnFinalizeSortingOrder -= UpdateHeldItemLayer;
            return;
        }
        SpriteRenderer rend = heldItem.GetComponent <SpriteRenderer>();

        if (rend == null)
        {
            som.OnFinalizeSortingOrder -= UpdateHeldItemLayer;
            return;
        }
        rend.sortingOrder = sortingOrder + (facingForward ? 1 : -1);

        SortingOrderManager heldSOM = heldItem.GetComponent <SortingOrderManager>();

        heldSOM?.OnFinalizeSortingOrder?.Invoke(facingForward ? rend.sortingOrder : rend.sortingOrder - 4);
    }
    void Update()
    {
        if (objectCarried == null && Input.touchCount == 1)
        {
            //on click, attempt to grab an object
            Touch touch = Input.GetTouch(0);

//			debug.text = "detected touch here!";
//			debug.transform.position = touch.position;

            Ray        ray = cam.ScreenPointToRay(touch.position);
            RaycastHit rch;
            debug.text = "Shooting raycast";
//			if (Physics.Raycast(transform.position, cam.gameObject.transform.forward, out rch, pickupRange)) {
            if (touch.phase == TouchPhase.Began &&
                Physics.Raycast(ray, out rch))
            {
                debug.text += "Raycast hit " + rch.collider.gameObject.name;

                if (rch.collider.gameObject.GetComponent <Grabbable>() != null &&
                    rch.collider.gameObject.GetComponent <Grabbable>().Interactive)
                {
                    debug.text += "\ntrying to grab " + rch.collider.gameObject.name;
                    //component is grabbable and interactive--grab it!
                    objectCarried = rch.collider.gameObject.GetComponent <Grabbable>();
                    objectCarried.GetComponent <Rigidbody>().isKinematic = true;
                    objectCarried.IsBeingHeld = true;
                }
            }
        }
//		else {
//			//throw bone
//			if (Input.GetKeyDown(KeyCode.Mouse0)) {
//				objectCarried.GetComponent<Rigidbody>().isKinematic = false;
//				objectCarried.IsBeingHeld = false;
//				//TODO: figure out how to properly add force to the throw
////				objectCarried.GetComponent<Rigidbody>().AddRelativeForce(cam.transform.forward * 200f);
//				objectCarried = null;
//			}
//		}
        if (objectCarried != null)
        {
            //if the object stops being interactive, stop carrying it
            if (!objectCarried.Interactive)
            {
                objectCarried = null;
            }
            else
            {
                //carry the object in front of the camera
                objectCarried.transform.position = cam.transform.position + cam.transform.forward;
            }
        }
    }
Exemple #20
0
    public void SetMesh(Grabbable grab)
    {
        ps_meshOutline.gameObject.SetActive(true);
        ps_meshOutline.transform.localScale = grab.transform.lossyScale;
        ps_meshOutline.transform.rotation   = grab.transform.rotation;
        var shape = ps_meshOutline.shape;

        shape.enabled       = true;
        shape.shapeType     = ParticleSystemShapeType.Mesh;
        shape.meshShapeType = ParticleSystemMeshShapeType.Edge;
        shape.meshSpawnMode = ParticleSystemShapeMultiModeValue.Loop;
        shape.mesh          = grab.GetComponent <MeshFilter>().mesh;
    }
    private void Ungrab()
    {
        if (grabbingGrabbable.transform.parent == transform || grabbingGrabbable.transform.parent == SnapTransform)
        {
            // detach the grabbable from grabber
            grabbingGrabbable.transform.SetParent(null, true);

            // apply controller's velocity to the detached grabbable to support "throw away"
            Vector3   velocity        = OVRInput.GetLocalControllerVelocity(controller);
            Vector3   angularVelocity = OVRInput.GetLocalControllerAngularVelocity(controller) * -1;
            Rigidbody rigidbody       = grabbingGrabbable.GetComponent <Rigidbody>();
            rigidbody.isKinematic     = false;
            rigidbody.velocity        = velocity;
            rigidbody.angularVelocity = angularVelocity;
        }
        grabbingGrabbable = null;
    }
 public void UseCurrentItem(InputAction.CallbackContext context)
 {
     if (canInteract && currentHoldingItem != null)
     {
         UsableGrabbable grabbable = currentHoldingItem.GetComponent <UsableGrabbable>();
         if (grabbable != null && grabbable.CheckUse())
         {
             if (context.started && grabbable.CheckUse())
             {
                 grabbable.Use();
             }
             if (context.canceled)
             {
                 grabbable.StopUse();
             }
         }
     }
 }
Exemple #23
0
    // Update is called once per frame
    void Update()
    {
        Grabbable objectCarried = player.getObjectCarried();

        if (objectCarried != null)
        {
            Bone bone = objectCarried.GetComponent <Bone>();
            if (bone != null)
            {
                hintUI.gameObject.SetActive(true);
                hintText.text = buildHintString(bone);
            }
        }
        else
        {
            hintUI.gameObject.SetActive(false);
        }
    }
 public void Throw(Vector3 dir)
 {
     if (grabbedObject != null)
     {
         Grabbable toThrow = grabbedObject;
         ReachOut(false);
         IRagdoll ragdoll = toThrow.GetComponent <IRagdoll> ();
         if (ragdoll != null)
         {
             ragdoll.ApplyVelocityToBones(dir * throwSpeed);
         }
         else
         {
             toThrow.rb.velocity = dir * throwSpeed;
         }
         canGrab = false;
         Invoke("EnableGrab", grabResetTime);
     }
 }
Exemple #25
0
    public void GrabObject(Grabbable prop)
    {
        if (prop.IsCosmetic())
        {
            Wear(prop);
            return;
        }

        float headHeight =
            collider.height / 2
            + prop.GetComponent <Collider>().bounds.extents.y / 2
            + collider.bounds.center.y;

        prop.BecomeHeldBy(transform, new Vector3(0f, headHeight, 0f));
        heldObject = prop;
        // Visuals
        sweat.Activate();
        anim.SetBool("Carrying", true);
        SoundPlayer.PlayWithRandomPitch("fb_raccoon_grabbing", 0.5f);
    }
    private void Grab(Grabbable grabbable)
    {
        grabbingGrabbable = grabbable;

        Rigidbody rigidbody = grabbable.GetComponent <Rigidbody>();

        rigidbody.isKinematic     = false;
        rigidbody.velocity        = Vector3.zero;
        rigidbody.angularVelocity = Vector3.zero;

        if (SnapTransform != null)
        {
            grabbable.transform.SetParent(SnapTransform, true);
            grabbable.transform.localPosition    = Vector3.zero;
            grabbable.transform.localEulerAngles = Vector3.zero;
        }
        else
        {
            grabbable.transform.SetParent(transform, true);
        }
    }
Exemple #27
0
    public void Release()
    {
        if (_currentGrabbable)
        {
            var newVelocity = _currentGrabbable.Rigidbody.velocity;

            newVelocity.x = Mathf.Clamp(newVelocity.x, -_releaseMaxVelocity, _releaseMaxVelocity);
            newVelocity.y = Mathf.Clamp(newVelocity.y, -_releaseMaxVelocity, _releaseMaxVelocity);
            newVelocity.z = Mathf.Clamp(newVelocity.z, -_releaseMaxVelocity, _releaseMaxVelocity);

            _currentGrabbable.Rigidbody.velocity         = newVelocity;
            _currentGrabbable.Rigidbody.useGravity       = true;
            _currentGrabbable.OnGrabbableCollisionEnter -= OnGrabbableCollisionEnter;
            _currentGrabbable.GetComponent <MonsterController>().Ungrab();

            _currentGrabbable = null;

            _attractionPosition.LookAt(transform);
            _attractionPosition.Rotate(new Vector3(0, 180, 0));
        }
    }
Exemple #28
0
    public void ReleaseObject(float disableGrabTime)
    {
        if (m_GrabbableScript)
        {
            if (m_SoundManager)
            {
                m_SoundManager.PlayRelease();
            }

            m_GrabbableScript.SetGrabber(null);
            var grabbedCollider = m_GrabbableScript.GetComponent <Collider2D>();
            grabbedCollider.isTrigger = false;
            Destroy(m_ConnectingJoint2D);
            m_ConnectingJoint2D = null;
            if (!m_bIsPlayer)
            {
                SendMessage("OnReleaseObject", disableGrabTime);
            }
            m_GrabbableScript = null;
            _grabDisabledTime = disableGrabTime;
        }
    }
Exemple #29
0
    public void Wear(Grabbable prop)
    {
        if (IsWearing())
        {
            Unwear();
        }
        var cos = prop.GetComponent <Cosmetic>();

        cos.BecomeWeared(headBone, color);

        // Update GM
        GameManager.instance.UpdatePlayer(
            index,
            new GameManager.Player()
        {
            index    = index,
            cosmetic = Library.instance.cosmetics.FindIndex(o => {
                return(o.GetComponent <Cosmetic>().uniqueID == cos.uniqueID);
            })
        }
            );

        hat = cos;
    }
Exemple #30
0
    void Absorb(Grabbable grabbable)
    {
        // ABSORB
        grabbable.GetProp().rigidbody.isKinematic = true;
        grabbable.GetProp().collider.enabled = false;

        AbsorbedObject ao = new AbsorbedObject();

        ao.obj           = grabbable.gameObject;
        ao.startPosition = grabbable.transform.position;
        ao.startSize     = grabbable.transform.localScale;
        absorbedObjects.Add(ao);

        SoundPlayer.PlayWithRandomPitch("fb_scoring_loot", 0.3f);
        if (!GameManager.instance.IsInGame())
        {
            var action = grabbable.GetComponent <ActionCube>();
            if (action != null)
            {
                switch (action.action)
                {
                case "startGame": GameManager.instance.NextLevel(); break;

                case "levelEditor": GameManager.instance.GoToLevelEditor(); break;

                case "saveLevel": GameManager.instance.SaveLevelWindow(); Instantiate(Library.instance.editorSaveLevelCube, new Vector3(), Quaternion.identity); break;
                }
            }
        }
        else if (GameManager.instance.IsInGame())
        {
            GameManager.instance.level.Score(grabbable);
            OnScoreChange();
        }
        Destroy(grabbable);
    }