-
-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Controller): move haptic feedback to controller actions
The `SteamVR_ControllerActions` is a more appropriate place to initiate an effect on the controller as it calls an action for the controller to do such as vibrate or show/hide it's model. A new example scene has been added to demonstrate the haptic rumble.
- Loading branch information
1 parent
422a7a9
commit e8e3bfe
Showing
9 changed files
with
149 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class Breakable_Cube : MonoBehaviour { | ||
float breakForce = 150f; | ||
|
||
void Start() | ||
{ | ||
this.GetComponent<Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous; | ||
} | ||
|
||
void OnCollisionEnter(Collision collision) | ||
{ | ||
if(collision.collider.name == "Sword" && collision.collider.GetComponent<Sword>().CollisionForce() > breakForce) | ||
{ | ||
foreach(Transform face in this.GetComponentsInChildren<Transform>()) | ||
{ | ||
if (face.transform.name == this.transform.name) continue; | ||
ExplodeFace(face); | ||
} | ||
Destroy(this.gameObject, 10f); | ||
} | ||
} | ||
|
||
void ExplodeFace(Transform face) | ||
{ | ||
face.transform.parent = null; | ||
Rigidbody rb = face.gameObject.AddComponent<Rigidbody>(); | ||
rb.isKinematic = false; | ||
rb.useGravity = true; | ||
rb.AddExplosionForce(500f, Vector3.zero, 0f); | ||
Destroy(face.gameObject, 10f); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class Sword : SteamVR_InteractableObject { | ||
SteamVR_ControllerActions controllerActions; | ||
Rigidbody rb; | ||
float impactMagnifier = 100f; | ||
float collisionForce = 0f; | ||
|
||
public float CollisionForce() | ||
{ | ||
return collisionForce; | ||
} | ||
|
||
public override void Grabbed(GameObject grabbingObject) | ||
{ | ||
base.Grabbed(grabbingObject); | ||
controllerActions = grabbingObject.GetComponent<SteamVR_ControllerActions>(); | ||
} | ||
|
||
private void Awake() | ||
{ | ||
rb = this.GetComponent<Rigidbody>(); | ||
rb.collisionDetectionMode = CollisionDetectionMode.Continuous; | ||
} | ||
|
||
private void OnCollisionEnter(Collision collision) | ||
{ | ||
if (controllerActions && IsGrabbed()) | ||
{ | ||
collisionForce = collision.impulse.magnitude * impactMagnifier; | ||
controllerActions.TriggerHapticPulse(40, (ushort)collisionForce); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters