//------------------------------------------------- private void OnCollisionEnter(Collision collision) { if (bParticlesSpawned) { return; } Hand collisionParentHand = null; BalloonHapticBump balloonColliderScript = collision.gameObject.GetComponent <BalloonHapticBump>(); if (balloonColliderScript != null && balloonColliderScript.physParent != null) { collisionParentHand = balloonColliderScript.physParent.GetComponentInParent <Hand>(); } if (Time.time > (lastSoundTime + soundDelay)) { if (collisionParentHand != null) // If the collision was with a controller { if (Time.time > (releaseTime + soundDelay)) // Only play sound if it's not immediately after release { collisionSound.Play(); lastSoundTime = Time.time; } } else // Collision was not with a controller, play sound { collisionSound.Play(); lastSoundTime = Time.time; } } if (destructTime > 0) // Balloon is released away from the controller, don't do the haptic stuff that follows { return; } if (balloonRigidbody.velocity.magnitude > (maxVelocity * 10)) { balloonRigidbody.velocity = balloonRigidbody.velocity.normalized * maxVelocity; } if (hand != null) { ushort collisionStrength = (ushort)Mathf.Clamp(Util.RemapNumber(collision.relativeVelocity.magnitude, 0f, 3f, 500f, 800f), 500f, 800f); hand.controller.TriggerHapticPulse(collisionStrength); } }
private void OnCollisionEnter(Collision collision) { if (this.bParticlesSpawned) { return; } Hand x = null; BalloonHapticBump component = collision.gameObject.GetComponent <BalloonHapticBump>(); if (component != null && component.physParent != null) { x = component.physParent.GetComponentInParent <Hand>(); } if (Time.time > this.lastSoundTime + this.soundDelay) { if (x != null) { if (Time.time > this.releaseTime + this.soundDelay) { this.collisionSound.Play(); this.lastSoundTime = Time.time; } } else { this.collisionSound.Play(); this.lastSoundTime = Time.time; } } if (this.destructTime > 0f) { return; } if (this.balloonRigidbody.velocity.magnitude > this.maxVelocity * 10f) { this.balloonRigidbody.velocity = this.balloonRigidbody.velocity.normalized * this.maxVelocity; } if (this.hand != null) { ushort durationMicroSec = (ushort)Mathf.Clamp(Util.RemapNumber(collision.relativeVelocity.magnitude, 0f, 3f, 500f, 800f), 500f, 800f); this.hand.controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0); } }