- Home /
Ricochet and wallhit sounds
Hi there.
I'm trying to get a sound when a bullet flies close to the player (on Java). I tried to get it working with two different scripts, two just for experiments, but not one of them works correctly.
I added a trigger collider to an empty on the player to define the 'proximity', empty have the tag 'ProximityCollider'.
My bullet is made by a particle with collision enabled and collision messaging, and its gameobject have the tag 'Projectile'. The script I added to the gameobject with the emitter on it works great by any collision of the particle on any surface. But not when it hits the player proximity collider.
The second script I added to the proximity box attached to the player. It sounds like a ricochet every time the collider collides, but not with a collision with the bullet.
(I suppose if the bullet particle triggers a sound by hitting a collider and the collisionbox of the player triggers a sound by collides with something, it should be possible to get a sound when the bullet hits the box!)
Script on the gameobject with particlesystem:
var audio1: AudioSource;
private var proxy: GameObject;
function Start(){
proxy = GameObject.FindGameObjectWithTag("ProximityCollider");
}
function OnParticleCollision(other: GameObject){
if(other.gameObject == proxy){
audio1.Play();
}
}
Script added to the proximity collider: var audio1: AudioSource;
function OnTriggerEnter(hit: Collider){
if(hit.gameObject.tag == "Projectile"){
audio1.Play();
}
}
I've tried a lot of variations, every other script I've wrote works (toggle flashlight with dust emitter, working inventory, HUD, dynamic areal music with fading, etc).
...
Thanks for helping.
Ten-thousands answers from the community to such simple dumb questions like "how to make sound when pressing a button?", but no one to a bit more specific and complex help request...
I heard once here are many profs around who could help... but no, what a paltry community -.-
It looks like you're using the legacy approach. Read the documentation carefully, and notice that the approach is different for Shuriken.
You could put a collider with trigger enabled on your bullet gameobject.