void Start() { m = this.GetComponent <MaestroInteractable>(); // rb = hand.GetComponent<Rigidbody>(); // speed = rb.velocity.magnitude; prev = hand.transform.position; }
public void Poof() { MaestroInteractable mi = this.gameObject.GetComponent <MaestroInteractable>(); if (mi != null && mi.isGrabbed) { return; } Debug.Log("Resetting " + gameObject.name); StartCoroutine("SpawnSmoke", this.gameObject.transform.position); if (disappear != null) { AudioSource.PlayClipAtPoint(disappear, this.gameObject.transform.position, 0.10f); } StartCoroutine("SpawnSmoke", this.position); /*if (appear != null) * AudioSource.PlayClipAtPoint(appear, this.position);*/ this.transform.SetPositionAndRotation(position, rotation); Rigidbody rb = this.GetComponent <Rigidbody>(); if (rb) { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.constraints = constraints; } }
private void Regrab(MaestroInteractable r, int finger0, int finger1) { if (r == null) { return; } Debug.Log("Regrabbing: " + finger0 + ", " + finger1); grabbing = true; regrabbed = true; Vector3 centroid = GetCentroid(contacts); if (!centroid.Equals(Vector3.negativeInfinity)) { Vector3 worldPos = grabTarget.transform.position; Quaternion worldRot = grabTarget.transform.rotation; grabPos.transform.position = centroid; grabTarget.transform.SetPositionAndRotation(worldPos, worldRot); } f1 = finger0; f2 = finger1; dist1 = (phystips[f1].transform.position - (grabTarget.gripCollider == null ? grabTarget.getFollowPoint() : Physics.ClosestPoint(phystips[f1].transform.position, grabTarget.gripCollider, grabTarget.gripCollider.transform.position, grabTarget.gripCollider.transform.rotation))).magnitude; //grabPos dist2 = (phystips[f2].transform.position - (grabTarget.gripCollider == null ? grabTarget.getFollowPoint() : Physics.ClosestPoint(phystips[f2].transform.position, grabTarget.gripCollider, grabTarget.gripCollider.transform.position, grabTarget.gripCollider.transform.rotation))).magnitude; //grabPos }
void OnCollisionExit(Collision c) { /*if (isvalid(c.collider) && c.collider.GetComponent<MaestroInteractable>().Equals(touching)) * { * touching = null; * }*/ if (c.collider.attachedRigidbody) { MaestroInteractable mi = c.collider.attachedRigidbody.GetComponent <MaestroInteractable>(); if (mi != null) { if (mi.Equals(touching)) { touching = null; TriggerTouching = false; } if (c.collider.GetComponentInParent <FingerTipCollider>() == null) { mi.Untouch(this); } } /*if (mi != null && c.collider.GetComponentInParent<FingerTipCollider>() == null) * { * mi.Untouch(this); * }*/ } netImpulse += c.impulse; }
public void CheckIfThrown(MaestroInteractable ball) { if (ball.GetComponent <Rigidbody>().velocity.magnitude >= throwSpeed) { isChecking = true; } }
// Use this for initialization void Start() { pulse = pulsers.GetComponentsInChildren <Pulser>(true); foreach (Pulser p in pulse) { p.gameObject.SetActive(false); } MaestroInteractable mi = this.GetComponent <MaestroInteractable>(); if (mi.onTouch == null) { mi.onTouch = new TouchEvent(); } mi.onTouch.AddListener(Register); if (mi.unTouch == null) { mi.unTouch = new TouchEvent(); } mi.unTouch.AddListener(Unregister); Reset(); }
private void TwoHandGrabStart(MaestroInteractable interactable, int index, int otherIndex) { if (interactable == null) { return; } twoHandGrabTarget = interactable; twoHandIndex = index; otherHand.twoHandGrabTarget = interactable; otherHand.twoHandIndex = otherIndex; twoHandGrabbing = true; initiatedTwoHandGrab = true; otherHand.twoHandGrabbing = true; otherHand.initiatedTwoHandGrab = false; timeSinceTwoHandGrabbing = 0.0f; interactable.rb.useGravity = false; if (interactable.maintainOrientation) { interactable.rb.constraints = RigidbodyConstraints.FreezeRotation; } interactable.Grab(LayerMask.NameToLayer(objectLayer)); }
protected override void GetResponse(MaestroInteractable parent) { if (impulseSum.magnitude > minImpulse) { CurrentAmp = (byte)Mathf.Min(255, parent.Amplitude + ((impulseSum.magnitude / (minImpulse * 100)) - 1)); CurrentDelay = 0f; Debug.Log("BONK: " + CurrentAmp); } if (CurrentAmp > parent.Amplitude) { parent.ResponseMotorAmplitude = CurrentAmp; parent.ResponseVibrationEffect = (byte)Mathf.Min(128, (CurrentAmp * 2)); } else { parent.ResponseMotorAmplitude = parent.ResponseVibrationEffect = null; } if (CurrentAmp > parent.Amplitude && CurrentDelay > (HitDelay * (StrengthScale + 1))) { CurrentAmp = (byte)(CurrentAmp * DecayRate); if (CurrentAmp < parent.Amplitude) { CurrentAmp = parent.Amplitude; } } impulseSum = Vector3.zero; CurrentDelay += Time.deltaTime; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); MaestroInteractable mi = target as MaestroInteractable; EditorGUILayout.HelpBox(DRV2605Descriptions.get(mi.VibrationEffect), MessageType.None, false); }
public LineSegment(Vector3 start, Vector3 end, MaestroInteractable interactable, int index, int otherIndex) { this.length = (start - end).magnitude; this.start = start; this.end = end; this.interactable = interactable; this.index = index; this.otherIndex = otherIndex; }
private void OnTriggerExit(Collider other) { MaestroInteractable temp = other.GetComponent <MaestroInteractable>(); if (temp != null && watching.Contains(temp)) { watching.Remove(temp); } }
void Start() { // Init Audio Sources buttonSource = TopDial.gameObject.AddComponent <AudioSource>(); buttonSource.playOnAwake = false; buttonSource.volume = 0.2f; topDialSource = TopDial.gameObject.AddComponent <AudioSource>(); topDialSource.playOnAwake = false; topDialSource.volume = 0.2f; topDialSource.pitch = 2f; bottomDialSource = BottomDial.gameObject.AddComponent <AudioSource>(); bottomDialSource.playOnAwake = false; bottomDialSource.volume = 0.2f; bottomDialSource.pitch = 1.0f; // Load Audio Clips topDialSource.clip = bottomDialSource.clip = Resources.Load <AudioClip>("Sounds/tumbler"); buttonSource.clip = btnDown = Resources.Load <AudioClip>("Sounds/button_down"); btnUp = Resources.Load <AudioClip>("Sounds/button_up"); // Init physics components Physics.IgnoreCollision(TopDial.gameObject.GetComponent <Collider>(), BottomDial.gameObject.GetComponent <Collider>(), true); top = TopDial.gameObject.GetComponent <ConfigurableJoint>(); bottom = BottomDial.gameObject.GetComponent <ConfigurableJoint>(); // Init events topRegister = bottomRegister = 0; if (onDialButtonPushed == null) { onDialButtonPushed = new UnityEvent(); } if (onDialButtonReleashed == null) { onDialButtonReleashed = new UnityEvent(); } // Init dial behavior start = TopDial.transform.localPosition; offset = top.linearLimit.limit; // Init haptics stuff mi = TopDial.gameObject.GetComponent <MaestroInteractable>(); mi2 = BottomDial.gameObject.GetComponent <MaestroInteractable>(); originalTopEffect = mi.VibrationEffect; originalBottomEffect = mi2.VibrationEffect; topFTCs = new List <FingerTipCollider>(); bottomFTCs = new List <FingerTipCollider>(); }
private void OnTriggerEnter(Collider other) { MaestroInteractable temp = other.GetComponent <MaestroInteractable>(); if (temp != null && temp.gameObject.layer != ignoreLayer) { //Debug.Log("OH THANK GOD"); if (!watching.Contains(temp) && temp.transform.position.y > this.transform.position.y) { watching.Add(temp); } } }
public void Start() { if (!Parent) { this.Parent = this.GetComponentInParent <MaestroInteractable>(); } if (!Parent) { Debug.Log("No MaestroInteractable on this object or any parent! Disabling component."); enabled = false; } }
void OnCollisionStay(Collision c) { if (isvalid(c.collider)) { //colnrm = c.contacts[0].normal; MaestroInteractable temp = c.collider.attachedRigidbody.GetComponent <MaestroInteractable>(); //if (temp.type != InteractionType.Static) //{ // make sure we're actually allowed to pick this up touchtemp = temp;// say what we're touching currently TriggerTouching = true; //} } }
private void OnTriggerExit(Collider other) { TriggerTouching = false; lastTouching = null; // TODO does this help? if (other.attachedRigidbody) { MaestroInteractable mi = other.attachedRigidbody.GetComponent <MaestroInteractable>(); if (mi && mi.Equals(touching)) { touching = null; } } //Debug.Log("EXIT"); }
// Update is called once per frame void Update() { elapsed += Time.deltaTime; if (elapsed > rate) { Vector3 dir = -gameObject.transform.right.normalized; if (parent.inputSource == SteamVR_Input_Sources.LeftHand) { dir *= -1; } elapsed %= rate; RaycastHit[] hits = Physics.SphereCastAll(gameObject.transform.position + getOffset(offset), 0.08f, dir, distance); MaestroInteractable found = null; bool change = false; foreach (RaycastHit hit in hits) { if ((found = getInteractable(hit)) != null && found.type != InteractionType.Static) { if (ignoreTwoHand && found.type == InteractionType.TwoHand) { continue; } change = true; break; } } if (change) { parent.rangeOfMotion = EVRSkeletalMotionRange.WithController; } else { parent.rangeOfMotion = EVRSkeletalMotionRange.WithoutController; } Debug.DrawRay(gameObject.transform.position + getOffset(offset), dir * distance, Color.red, rate); } }
void Update() { //update the public touching variable and reset touchtemp so it has to be set again by OnCollisionStay during the next frame if (touchtemp != null) { touching = touchtemp; touchtemp = null; } if (rb) { lastLocation = this.rb.position; } else { lastLocation = this.transform.position; } //this mess just resets the finger clamping after 0.2 seconds of not touching anything if (touching) { timer = 0; lastTouching = touching; } else { timer += Time.deltaTime; /*if (index < 5 && timer > 0.2f) * { * hpi.hc.SetClamp(index, 0); * }*/ } }
private GameObject getCylinderBetween(Transform a, Transform b) { GameObject result = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Rigidbody rb = result.AddComponent <Rigidbody>(); rb.mass = mass; rb.drag = drag; rb.useGravity = false; result.layer = layer; cylinders.Add(result); //Collider temp = result.GetComponent<Collider>(); //TODO remove CylinderBetween cb = result.AddComponent <CylinderBetween>(); MaestroInteractable mi = result.AddComponent <MaestroInteractable>(); mi.type = InteractionType.Static; mi.IgnoreTaps = true; mi.Amplitude = 255; mi.VibrationEffect = 2; //Physics.IgnoreCollision(temp, a.GetComponent<Collider>(), true); //Physics.IgnoreCollision(temp, b.GetComponent<Collider>(), true); cb.a = a; cb.b = b; cb.size = size; //cb.Init(); SpringJoint sj = a.gameObject.AddComponent <SpringJoint>(); sj.damper = damper; sj.spring = spring; sj.connectedBody = b.gameObject.GetComponent <Rigidbody>(); sj.minDistance = 0.001f; sj.maxDistance = 0.05f; sj.enablePreprocessing = false; return(result); }
protected abstract void GetResponse(MaestroInteractable parent);
private void GrabEnd(bool drop) { if (drop) { // Try regrab bool grabStarted = false; for (int i = 0; i < contacts.Length; i++) { if (phystips[i].touching != null && !grabStarted) { grabStarted |= checkFingerGrabbing(i); } } if (grabStarted) { contacts = new bool[11]; } // Drop only if regrab failed if (!grabStarted) { Debug.Log("Dropping" + timeSinceGrabbing); grabTarget.rb.constraints = oldConstraints; grabTarget.rb.AddForce(getThrowVelocity(), ForceMode.Force); grabTarget.transform.parent = oldParent; oldParent = null; //release the thing grabTarget.rb.useGravity = oldGravity; grabTarget.rb.isKinematic = oldKinematic; //grabTarget.rb.freezeRotation = false; // Tell the MaestroInteractable it was released grabTarget.Release(); // Reset grab position and contacts grabPos.transform.DetachChildren(); Destroy(grabPos); contacts = new bool[11]; lastTargetWasTool = grabTarget.isTool; grabTarget = null; timeSinceRelease = 0.0f; grabbing = false; } } else { //if drop is false, a different hand has taken control of the thing and we don't need to worry about detaching it grabPos.transform.DetachChildren(); lastTargetWasTool = grabTarget.isTool; Destroy(grabPos); grabbing = false; timeSinceRelease = 0.0f; grabTarget = null; contacts = new bool[11]; } }
public void setInteractableAmplitude(MaestroInteractable mi) { mi.setAmplitudeFromScale(value); }
// Start is called before the first frame update void Start() { knob = this.GetComponent <MaestroInteractable>(); }
private void FixedUpdate() { // Update contact bools regrabbed = false; for (int i = 0; i < contacts.Length; i++) { contacts[i] = phystips[i].TriggerTouching; } bool palmTouch = contacts[colliders.Length - 1]; // Update all haptics for (int i = 0; i < pulls.Length; i++) { if (pulls[i].DribbleOverride) { pulls[i].Amplitude = 255; vibs[i].VibrationEffect = 5; pulls[i].DribbleWait += Time.fixedDeltaTime; //wait some time if (pulls[i].DribbleWait >= DribbleLengthener.MinDribbleWait) { pulls[i].DribbleOverride = false; } } else { if (grabTarget != null && grabTarget.SendHapticsToWholeHand) { pulls[i].Amplitude = grabTarget.getMotorAmplitude(); vibs[i].VibrationEffect = grabTarget.getVibrationEffect(); } else { MaestroInteractable mi = phystips[i * 2 + 1].touching; if (mi != null) { pulls[i].Amplitude = mi.getMotorAmplitude(); } else if (palmTouch && phystips[colliders.Length - 1].touching != null) { byte?amp = phystips[colliders.Length - 1].touching.getMotorAmplitude(); if (amp.HasValue) { pulls[i].Amplitude = (byte)(amp.Value * 0.65f); } } else { mi = phystips[i * 2].touching; //test knuckle if (!(palmTouch && phystips[colliders.Length - 1].touching != null)) { if (mi != null) { pulls[i].Amplitude = mi.getMotorAmplitude(); } else { pulls[i].Amplitude = null; } } else { byte?amp = phystips[colliders.Length - 1].touching.getMotorAmplitude(); if (amp.HasValue) { pulls[i].Amplitude = (byte)(amp.Value * 0.65f); } } //pulls[i].Amplitude = null; mi = phystips[i * 2 + 1].touching; } if (mi != null) { vibs[i].VibrationEffect = mi.getVibrationEffect(); } else { vibs[i].VibrationEffect = null; } //TODO REMOVE /*if (i == 1 && whichHand == WhichHand.RightHand) * { * MaestroInteractable herk = phystips[i * 2 + 1].lastTouching; * MaestroBLEUI.SetRightText(String.Format("{0}\r\n{1}\r\n{2}", * mi != null ? mi.name : "NULL", * herk != null ? herk.name : "NULL", * vibs[i].VibrationEffect ?? 0)); * }*/ /*else if (palmTouch && phystips[colliders.Length - 1].touching != null) * { * vibs[i].VibrationEffect = phystips[colliders.Length - 1].touching.getVibrationEffect(); * }*/ } } } // Update all time variables timeSinceGrabbing += Time.fixedDeltaTime; timeSinceRelease += Time.fixedDeltaTime; timeSinceTwoHandGrabbing += Time.fixedDeltaTime; // Move all temp FTCs and check what they're touching // TODO merge with others for (int j = 0; j < extras.Length; j++) { int i = j + colliders.Length; // turn off finger colliders if I'm grabbing something or just let go of it phystips[i].col.enabled = lastTargetWasTool ? timeSinceRelease > 0.5f : true; //move the fingertip + palm colliders to the right place. Because I'm setting velocity, there's no guarantee they'll actually get there (ex. if there's something heavy in the way) Vector3 dist = (extras[j].transform.position - phystips[i].rb.position); Vector3 lastLocation = phystips[i].lastLocation; if (dist.magnitude > tooFast && (lastLocation - phystips[i].rb.position).magnitude < tooClose) { phystips[i].rb.transform.position = extras[j].transform.position; } else { phystips[i].rb.velocity = dist / Time.deltaTime; } phystips[i].rb.MoveRotation(extras[j].transform.rotation); phystips[i].rend.enabled = showColliders; //if the fingertip is touching something, and I'm not currently holding anything, check if there's more than one finger holding onto it. if (phystips[i].touching != null && !grabbing) { checkFingerGrabbing(i); } /*if (otherHand != null && phystips[i].touching != null && !twoHandGrabbing && phystips[i].touching.type == InteractionType.TwoHand) * { * checkTwoHandGrabbing(i); * }*/ } // Move all FTCs and check what they're touching for (int i = 0; i < colliders.Length; i++) { phystips[i].col.enabled = lastTargetWasTool ? timeSinceRelease > 0.5f : true; // turn off finger colliders if I'm grabbing something or just let go of it //move the fingertip + palm colliders to the right place. Because I'm setting velocity, there's no guarantee they'll actually get there (ex. if there's something heavy in the way) Vector3 dist = (colliders[i].transform.position - phystips[i].rb.position); Vector3 lastLocation = phystips[i].lastLocation; if (dist.magnitude > tooFast && (lastLocation - phystips[i].rb.position).magnitude < tooClose) { phystips[i].rb.transform.position = colliders[i].transform.position; } else { phystips[i].rb.velocity = dist / Time.deltaTime; } //phystips[i].rb.velocity = (colliders[i].transform.position - phystips[i].rb.position) / Time.deltaTime; phystips[i].rb.MoveRotation(colliders[i].transform.rotation); phystips[i].rend.enabled = (phystips[i].isTip && !phystips[i].PaintColor.Equals(Color.clear)) || (showColliders && contacts[i]); //if the fingertip is touching something, and I'm not currently holding anything, check if there's more than one finger holding onto it. if (phystips[i].touching != null && !grabbing) { checkFingerGrabbing(i); } } recordPalmLocation(phystips[colliders.Length - 1].rb.transform.position); // If the user has two hands defined, check if two-hand grab has started if (otherHand != null && !twoHandGrabbing && !otherHand.twoHandGrabbing) { checkTwoHandGrabbing(); } // Update started bools grabStarted = !wasgrabbing && grabbing; twoHandGrabStarted = !wasTwoHandGrabbing && twoHandGrabbing; // Play pickup noise if necessary if (grabStarted && audioSource != null) { audioSource.pitch = 2 + UnityEngine.Random.value; audioSource.Play(); } // Update one-hand grabs if necessary if (grabbing) { OnGrabbing(); } else { grabStarted = false; } // Update two-hand grabs if necessary if (twoHandGrabbing && initiatedTwoHandGrab) { OnTwoHandGrabbing(); } else { twoHandGrabStarted = false; } // Update was bools wasgrabbing = grabbing; wasTwoHandGrabbing = twoHandGrabbing; // Move grab anchor if necessary if (grabbing && grabPos != null && !grabTarget.isTool && !grabStarted) { Vector3 centroid = GetCentroid(contacts); Vector3 temp = Vector3.Lerp(grabPos.transform.position, centroid, Time.fixedDeltaTime * scaler); if (!(temp.Equals(Vector3.negativeInfinity) || grabTarget.maintainPosition)) { grabPos.transform.position = temp; } } foreach (PullOnCollideBehaviour p in pulls) { if (p != null) { p.Prop(); } } foreach (VibrateOnCollideBehaviour v in vibs) { if (v != null) { v.Prop(); } } }
private void GrabStart(MaestroInteractable r, int finger0, int finger1) { if (r == null) { return; } Debug.Log("Start grab: " + finger0 + ", " + finger1); grabTarget = r; timeSinceGrabbing = 0; grabbing = true; grabPos = generateAnchor(grabTarget.isTool ? colliders[10].transform.position : grabTarget.getFollowPoint()); //grabPos.transform.rotation = Quaternion.identity; if (otherHand != null && otherHand.grabbing && otherHand.grabTarget == this.grabTarget) { oldParent = otherHand.oldParent; oldGravity = otherHand.oldGravity; oldKinematic = otherHand.oldKinematic; otherHand.GrabEnd(false); } else { oldParent = grabTarget.transform.parent; oldGravity = grabTarget.rb.useGravity; oldKinematic = grabTarget.rb.isKinematic; } grabTarget.rb.useGravity = false; oldConstraints = grabTarget.rb.constraints; if (oldConstraints == RigidbodyConstraints.None) { Vector3 worldPos = grabTarget.transform.position; Quaternion worldRot = grabTarget.transform.rotation; grabTarget.transform.parent = grabPos.transform; grabTarget.transform.SetPositionAndRotation(worldPos, worldRot); //grabTarget.transform.localPosition = Vector3.zero; } if (grabTarget.maintainOrientation) { grabTarget.rb.constraints |= RigidbodyConstraints.FreezeRotation; } grabTarget.rb.isKinematic = false; f1 = finger0; f2 = finger1; dist1 = (phystips[f1].transform.position - (grabTarget.gripCollider == null ? grabTarget.getFollowPoint() : Physics.ClosestPoint(phystips[f1].transform.position, grabTarget.gripCollider, grabTarget.gripCollider.transform.position, grabTarget.gripCollider.transform.rotation))).magnitude; //grabPos dist2 = (phystips[f2].transform.position - (grabTarget.gripCollider == null ? grabTarget.getFollowPoint() : Physics.ClosestPoint(phystips[f2].transform.position, grabTarget.gripCollider, grabTarget.gripCollider.transform.position, grabTarget.gripCollider.transform.rotation))).magnitude; //grabPos // Tell the Interactable it's been grabbed by this script r.Grab(LayerMask.NameToLayer(objectLayer)); }
public void setInteractableEffect(MaestroInteractable mi) { mi.setEffectFromScale(value); }
void OnCollisionEnter(Collision c) { //Debug.Log("e;alskjdf;la"); if (c.collider.attachedRigidbody) { MaestroInteractable mi = c.collider.attachedRigidbody.GetComponent <MaestroInteractable>(); if (mi != null && c.collider.GetComponentInParent <FingerTipCollider>() == null) { mi.Touch(this); //Debug.Log("TOUCH!"); //hpi.hc.TriggerHaptics(600); timer = 0; //time to set the clamp value. The finger just touched the thing we're holding, so we don't want it to bend more. //index < 5 because index = 5 means this is the palm. Which doesn't bend. /*if (index < 5 && hpi.grabTarget == c.rigidbody) * { * hpi.hc.SetClamp(index, hpi.hc.getposfromindex(index)); * }*/ //c.rigidbody.GetComponent<MaestroInteractable>().Touch(this); // tell the Interactable it got touched by this finger if (!mi.IgnoreTaps) { float scale = 1.50f; float helper = Mathf.Max(0.20f, Mathf.Min(1.0f, this.rb.velocity.magnitude * scale)); if (vocb) { vocb.PulseEffect = (byte)(128 * source.volume); vocb.pulseHalfLife = 0.3f; } if (vocbs != null && vocbs.Length > 0) { foreach (VibrateOnCollideBehaviour v in vocbs) { if (v != null && source != null) { v.PulseEffect = (byte)(128 * source.volume); v.pulseHalfLife = 0.3f; } } } if (source != null && mi.type == InteractionType.Static /*&& mi.type == InteractionType.Static*/) { source.volume = helper; source.Play(); } } } } /*MeshDeformer md = c.gameObject.GetComponent<MeshDeformer>(); * if (md) * { * md.AddDeformingForce(c.contacts[0].point, 10f); * }*/ }