//checks a surrounding sphere for objects, grabs them private void GrabObject() { if (holding) { return; } heldObject = null; if (velocity.magnitude > 100) { return; } Grabbable grabTarget = GetClosestObject(); if (grabTarget == null) { StartCoroutine(gracePeriod()); return; } grabTarget.Grab(this); heldObject = grabTarget; foreach (Collider col in _myColliders) { if (col != grabCollider) { col.enabled = false; } } }
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; }
protected virtual void OnArrowNocked(HVRArrow arrow) { _previousArrowSleep = arrow.Rigidbody.sleepThreshold; arrow.transform.rotation = Quaternion.LookRotation(WorldForward, NockSocket.transform.up); arrow.transform.position = NockSocket.transform.position; var grabbable = arrow.Grabbable; grabbable.ForceRelease(); grabbable.CanBeGrabbed = false; grabbable.Rigidbody.sleepThreshold = 0f; grabbable.Grabbed.AddListener(OnNockedArrowGrabbed); UpdateBowHandCollision(BowHand, grabbable, false); NockSocket.AllowGrabbing = false; Arrow = arrow; Grabbable.IgnoreCollision(grabbable); if (NockHand) { NockHand.TryGrab(NockGrabbable, true); NockHand = null; } arrow.EnableForwardGrabbable(); }
private void TryGrab() { if (isGrabbing) { // pickup if (grabbedObject == null) { Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 1.5f, 1 << 12); // 12 = Grabbable foreach (Collider2D hit in hits) { Grabbable grabComponent = hit.gameObject.GetComponent <Grabbable>(); if (grabComponent.owner == null) { grabComponent.Pickup(this); grabbedObject = grabComponent; break; } } } else // drop { DropGrabbedObject(true); } } }
private void OnTriggerEnter(Collider other) { Grabber testedGrabber = other.gameObject.GetComponent <Grabber>(); if (testedGrabber == null) { return; } grabber = testedGrabber; grabber.Drop += OnGrabRelease; Debug.Log(gameObject.name + " Enter Triger: " + other.gameObject.name, other.gameObject); if (grabber.HeldGrabbable == null) { Debug.Log("Held Item null Trigger Enter"); return; } Debug.Log("Trzyma item:" + grabber.HeldGrabbable.name); iteamReadyToSnap = grabber.HeldGrabbable; if (iteamReadyToSnap == null) { Debug.Log("Held item is null"); } if (iteamReadyToSnap && AreSnapConditionsMet()) { Snap(); } }
private void GripDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) { gripInput = -1f; int i = FindGrabbable(); if (i < 0) { return; } Grabbable gb = grabArray[i]; if (gb.obj != null) // Is the object an useable tool? { gb.obj.GrabAction(transform); assignedController.GrabObject(gb.obj); currentGrab.rbody = gb.rbody; currentGrab.obj = gb.obj; // Clear the grab array at this point grabArray.Clear(); // Hide the hand model and colliders //model.SetActive(false); } }
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); } }
bool Grab() { foreach (Collider2D near in Physics2D.OverlapCircleAll(body.position, grabRange)) { if (near.gameObject == gameObject) { continue; } Grabbable grabbable = near.GetComponent <Grabbable>(); if (grabbable && !grabbable.IsGrabbed) { Debug.Log("Grabbing " + grabbable); GrabThrow otherGrabThrow = near.GetComponent <GrabThrow>(); if (!otherGrabThrow || otherGrabThrow.Grabbed != gameObject) { Grabbed = near.gameObject; Grabbed.transform.parent = transform; Grabbed.transform.localPosition = new Vector2(carryOffsetX * move.Facing, carryOffsetY); grabbable.IsGrabbed = true; grabbedBody = near.GetComponent <Rigidbody2D>(); grabbedBody.angularVelocity = 0; grabbedBody.simulated = false; return(true); } } } return(false); }
private void OnTriggerStay(Collider other) { float handTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, myHand); Rigidbody otherRB = other.attachedRigidbody; if (otherRB == null) { return; } Grabbable g = otherRB.GetComponent <Grabbable>(); if (g == null) { return; } //we know it's a grabbable if (handTrigger > gripAtPercentage && grabbed == null) { grabbed = g; handGraphics.SetActive(false); Logger.log("grabbed " + this.follow.name); grabOffset.transform.position = g.transform.position; grabOffset.transform.rotation = g.transform.rotation; if (g.useExact) { g.grab(grabOffset); } else { g.grab(rb.transform); } } }
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; } } }
private bool CanMoveGrabbable(Grabbable g, Vector2 pos) { Vector2 size = g.GetSize(); RaycastHit2D[] hits = Physics2D.BoxCastAll(pos, size, 0, Vector2.zero, 0, LayerMask.GetMask("LevelGeometry")); return(hits.Length == 0 || (hits.Length == 1 && hits[0].collider.gameObject == g.gameObject)); }
// Start is called before the first frame update void Start() { m_SoundManager = GetComponent <SoundManager>(); m_ConnectingJoint2D = null; m_GrabbableScript = null; _grabDisabledTime = 0; }
private void OnTriggerStay(Collider other) { float handTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, myHand); Rigidbody otherRB = other.attachedRigidbody; if (otherRB == null) { return; } Grabbable g = otherRB.GetComponent <Grabbable>(); if (g == null) { return; } //we know it's a grabbable if (handTrigger > gripAtPercentage && grabbed == null) { grabbed = g; handGraphics.SetActive(false); StartCoroutine(doVibrate(.2f)); Logger.log("grabbed " + this.follow.name); g.grab(this.follow); } }
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; } }
static void Main(string[] args) { Model cubeModel; Model sphereModel; if (!StereoKitApp.Initialize("MessingWithBounds", Runtime.MixedReality)) { Environment.Exit(1); } // Creating models cubeModel = Model.FromMesh( Mesh.GenerateCube(Vec3.One * 0.25f), Default.Material ); sphereModel = Model.FromMesh( Mesh.GenerateSphere(0.15f), Default.Material ); // Creating grabbable versions of the above models Grabbable grabbableCube = new Grabbable(ref cubeModel, new Vec3(-0.25f, 0f, 0f)); Grabbable grabbableSphere = new Grabbable(ref sphereModel, new Vec3(0.25f, 0f, 0f)); while (StereoKitApp.Step(() => { grabbableCube.Update(); grabbableSphere.Update(); })) { ; } StereoKitApp.Shutdown(); }
IEnumerator SpotRaccoon(PlayerController pc) { seenPlayer = pc; look.FocusOn(seenPlayer.transform); if (seenPlayer != lastSeenPlayer) { RememberPlayer(seenPlayer); } else if (seenPlayer.GetHeldObject() == null) { yield break; } SuprisedBy(seenPlayer.transform.position); emotion.Show("Think"); yield return(new WaitForSeconds(reactionTime)); emotion.Hide(); if (seenPlayer == null || stun) { yield break; } seenItem = seenPlayer.GetHeldObject(); if (seenItem != null) { ChangeState(HumanState.Chasing); } else { ChangeState(HumanState.Walking); } }
private void OrderIsRight(List <Item> itens) { List <Grabbable> itensToGrab = new List <Grabbable>(); for (int i = 0; i < itens.Count; i++) { Grabbable item = itens[i].GetComponent <Grabbable>(); if (item.isGrabbed) { Grabbable parent = item.grabParent.GetComponent <Grabbable>(); if (!itensToGrab.Contains(parent)) { itensToGrab.Add(parent); } } else { if (!itensToGrab.Contains(item)) { itensToGrab.Add(item); } } } //Return the objects ReturnObjectsToPool(itens); Debug.Log($"Order correct! The delivery guy will take these itens [{string.Join(" - ", itensToGrab.Select(x => x.name))}]"); orderDelivered?.Invoke(true, itens.Count); }
private Grabbable GetClosestObject() { Grabbable closest = null; Vector3 p = grab_position.transform.position; float distance = Mathf.Infinity; if (_onBounds.Count > 0) { foreach (Collider g in _onBounds) { if (g != null) { Vector3 diff = g.ClosestPointOnBounds(p) - p; float current_distance = diff.sqrMagnitude; Grabbable grabbable = g.gameObject.GetComponent <Grabbable>(); if (current_distance < distance && grabbable != null) { distance = current_distance; closest = grabbable; } } } } return(closest); }
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; } }
public override bool OnCollision(Fixture f1, Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact) { CollidingSprite other = SyncedGameCollection.GetCollisionComponent(f2); if (other != null) { if (other.Tag == TagCategories.CRYSTAL) { Grabbable g_other = (Grabbable)other; if (g_other.HasOwner) { if (g_other.Owner.ID == _start.ID || g_other.Owner.ID == _end.ID) { return(false); } else { g_other.ForcedRelease(); return(true); } } else { return(true); } } } return(true); }
public void EndGrab() { grabbedObject.OnGrabEnd (); grabbedObject = null; if (stareInput != null) stareInput.enabled = true; }
void throwHeldObject() { Grabbable thing = heldObject; ungrab(); thing.GetComponent <Rigidbody> ().AddForce(Camera.main.transform.forward * 10, ForceMode.Impulse); }
public void Throw() { currentGrab.Throw(throwForce); onThrow.Invoke(); currentGrab.onFree.RemoveListener(Free); currentGrab = null; }
void Snap() { Debug.Log("Snap"); snapState = SnapState.IsWaitingForRelease; Array.ForEach(snapAreaEnters, s => s.SnapEnter(iteamReadyToSnap)); snappedItem = iteamReadyToSnap; }
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> ()); } } } }
private void AffectObjectsInBeam() { HashSet <GameObject> objects = beam.ObjectsInBeam; foreach (GameObject toAffect in objects) { HealthTracker health = toAffect.GetComponent <HealthTracker>(); if (health) { health.InflictDamage(agentDamageRate * Time.deltaTime); } else { Grabbable grabbable = toAffect.GetComponent <Grabbable>(); if (grabbable != null && grabbable.IsGrabbed) { grabbable.Release(); } else if (attract && !repel && Vector3.Distance(toAffect.transform.position, attachmentPoint.transform.position) <= autoGrabRange && toAffect.GetComponent <MergableObject>().Size <= maxGrabSize) { GrabObject(toAffect); } else { ApplyForceToObject(toAffect); } } } }
void ChangeState(HumanState newState) { switch (newState) { case HumanState.Walking: seenItem = null; seenPlayer = null; targetSpeed = walkSpeed; look.LooseFocus(); emotion.Hide(); MoveTo(currentWaypoint); break; case HumanState.Thinking: targetSpeed = 0; SoundPlayer.PlayAtPosition("si_concerned_human", transform.position, 0.1f, true); break; case HumanState.Chasing: emotion.Show("Suprised"); targetSpeed = chaseSpeed; SoundPlayer.PlayAtPosition("si_raccoon_spotted", transform.position, 0.1f, false); break; case HumanState.Collecting: seenPlayer = null; break; } state = newState; }
public void Reset() { transform.position = originalPosition; transform.rotation = originalRotation; sr.transform.localScale = originalScale; stretchAmount = 0f; stretchDirection = Vector2.up; anim.SetBool("Moving", false); anim.SetBool("Grabbing", false); CurrentTile = Physics2D.OverlapBox(originalPosition, Vector2.one * 0.9f, 0, RealTileMask).GetComponent <RealTile>(); if (HasKey) { miniKeyActual = 0f; Grabbable.Reset(); Grabbable = null; miniKey.color = Color.clear; } if (activeRoutine != null) { StopCoroutine(activeRoutine); } DestroyDupe(); }
IEnumerator PickUp(GameObject obj) { // Look at the object Vector3 direction = obj.transform.position - transform.position; direction = new Vector3(direction.x, transform.position.y, direction.z); transform.forward = direction; look.LooseFocus(); Grabbable grab = obj.GetComponent <Grabbable>(); if (grab != null) { grab.BecomeHeldBy(handBone); } ChangeState(HumanState.Thinking); anim.SetTrigger("Pickup"); yield return(new WaitForSeconds(1f)); if (seenItem != null && seenItem.gameObject != null) { Destroy(seenItem.gameObject); } // Return to normal state ChangeState(HumanState.Walking); if (path.Count > 0) { MoveTo(0); } }
private void Awake() { Grabbable = GetComponent <Grabbable>(); AudioSource = GetComponent <AudioSource>(); Collider = GetComponentInChildren <Collider>(); TerrainLayer = LayerMask.NameToLayer("Terrain"); }
public Grabbable GetClosestGrabbableInRadius(Vector3 position, float distance) { Grabbable closestGrabbable = null; int numGrabbables = m_grabbables.Count; for (int i = 0; i < numGrabbables; i++) { Grabbable grabbable = m_grabbables[i]; float separation = Vector3.Distance(grabbable.transform.position, position); if (separation < distance) { if (closestGrabbable == null) { closestGrabbable = grabbable; } else if (separation < Vector3.Distance(closestGrabbable.transform.position, position)) { closestGrabbable = grabbable; } } } return(closestGrabbable); }
protected virtual void Release() { GrabbedObject.Released(); GrabbedObject = null; if (ReleaseEvent != null) ReleaseEvent(this, EventArgs.Empty); grabbing = false; }
void OnTriggerEnter(Collider col){ if (doorIsLocked && col.gameObject.layer == LayerMask.NameToLayer("Mags")) { //tells player to let go unlockMag = P_HoldingScript.instance.grabObj; //magnet to use P_HoldingScript.instance.ForceLetGo(); //puts it in middle doorIsLocked = false; } }
protected virtual void Grab() { if (_PotentialGrabbables.Count > 0) { Grabbable grabbable = _PotentialGrabbables.First(); grabbable.Grabbed(this); GrabbedObject = grabbable; if (GrabEvent != null) GrabEvent(this, EventArgs.Empty); grabbing = true; } }
public void Grab(){ if (Physics.Raycast (Camera.main.transform.position, Camera.main.transform.forward, out grabHit) && !isGrabbing) { //raycast out of cam if (grabHit.collider.gameObject.GetComponent<Grabbable> () != null) { //checks if object has grabable class attatche //Debug.Log ("Grabbed."); grabObj = grabHit.collider.transform.GetComponent<Grabbable> (); if (grabObj.canGrab) { //checks if can be grabbed isGrabbing = true; grabObj.StartGrab (); //starts grab } } else { //Debug.Log ("Cant Grab that."); } } else { //Debug.Log ("Nothing to grab."); } }
void OnCollisionEnter(Collision col) { if (this.GetComponent<Rigidbody>().velocity.magnitude > 3.5f) { //AudioSource.PlayClipAtPoint(bumpClip, Vector3.zero, .75f); bumpSource.pitch = Random.Range(.75f, 1.25f); bumpSource.Play(); Vector3 diff = col.contacts[0].point - this.transform.position;//(col.contacts[0]. - this.transform.position); float squashAmt = fruitGfx.transform.localScale.x / 1.5f; if (Mathf.Abs(diff.x) > Mathf.Abs(diff.y)) { iTween.PunchScale(this.fruitGfx, new Vector3(-squashAmt, squashAmt,0), 1f); } else { iTween.PunchScale(this.fruitGfx, new Vector3(squashAmt, -squashAmt, 0), 1f); } Invoke("resetFruitScale", 1.1f); } if (col.gameObject.GetComponent<Copter>() != null && col.gameObject.transform.position.y > this.transform.position.y) { print("drop hat!"); if (hat != null) { AudioSource.PlayClipAtPoint(releaseSound, Vector3.zero); hat.grabber = col.gameObject; this.hat = null; } } }
void OnDropped(Grabbable item) { // do stuff?!?!? Debug.Log("dropped " + item.name + " in dropzone : " + gameObject.name); GetComponent<SignalSender>().Send(); }
public void StartGrab(GameObject obj, Camera cam, float dist) { if (dist < MinimumDistance || obj.GetComponent<Grabbable>() == null) return; // Save object references grabbedObject = obj.GetComponent<Grabbable> (); grabbedObject.OnGrabStart (Damping, AngularDamping); this.cam = cam; if (stareInput != null) stareInput.enabled = false; // Offset is where the object was grabbed, relative to the object's transform offset = grabbedObject.transform.InverseTransformPoint (cursor.transform.position); distance = dist; startingImageDistance = ImageTarget.localPosition.z; // Reset drop stuff shakeCounter = 0; lastShakeVel = new Vector3 (); lastShakePoint = GetShakePoint (); }
void Awake(){ rb = GetComponent<Rigidbody> (); grb = GetComponent<Grabbable> (); //rb.isKinematic = true; }