Greetings,
Has anyone succeeded in using physics property to generate sound in Unity? (ex glass/concrete… like in unreal and source)
Greetings,
Has anyone succeeded in using physics property to generate sound in Unity? (ex glass/concrete… like in unreal and source)
I haven’t worked with the Unreal or Source engines, but in Unity the Physics properties and the Sound component are two different things. Having said that, you can set up your scene so that an object with the tag “concrete” will have a certain phyics property and audio clip and another object with a “glass” tag will have a different physics property and sound. Is that what you’re looking for or did I misunderstand your question?
That’s what I’m looking for - and so I would have to coded a GameObject listening to collisions messages sent by physics objects then reading their tags to generate appropriate sounds?
Off the top of my head I’d do something like this:
Create a new phyics material called “Concrete”.
Add a collider to your object and set the physics material to “Concrete”.
Create a new tag called “Concrete” and set the object’s tag to it.
Attach an audio source with your “collision with concrete” sound and attach it to the object.
Make sure your player camera has an audio listener.
Write a script that includes something like:
var ConcreteTag : String; // your object tag
var ConcreteSound : Audioclip; // your concrete collision sound.
function OnCollisionEnter (col : Collision) {
if (col.gameObject.tag == ConcreteTag) {
audio.PlayOneShot(ConcreteSound);}
}
There might be a nicer way to accomplish this, but I’m pretty sure this will work.
If you like, you could also read the name of the physics material directly from collider.material.name, which would allow you to save tags for other things.
–Eric
Thanks I was about to ask for more tags
(yes I’m evaluating Unity to the bone)
What in your experience is the fastest method?
I’m not sure which is fastest, but I think it won’t make any difference, since OnCollisionEnter probably won’t be called very often (relatively speaking).
–Eric