x


How to detect collisions between particles and a collider?

hi im pretty new to unity well not realy new i no the interface well and how it all works but i am making a zombie game and you need to collect particles for special powers and i've made the particle edmiter and atached the box collider but what i want to do is when you walk into the particle it plays a sound and the particle disapers now if you could please give me some detailed code and instuctions it would be very much appreciated thanks.

more ▼

asked Mar 25 '10 at 12:00 PM

user-1761 (yahoo) gravatar image

user-1761 (yahoo)
11 1 2 4

As we all do.. be more creative with the title... :)

Mar 25 '10 at 12:40 PM Lipis
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You can use the ParticleCollider to create collision between the player and a particle. By implementing the OnParticleCollision() method on a component attached to the player you can detect when you've hit a particle, and then take the appropriate action.

more ▼

answered Mar 25 '10 at 01:07 PM

KvanteTore gravatar image

KvanteTore
1.5k 8 15 33

(comments are locked)
10|3000 characters needed characters left

You could place a box collider around the whole emitter, then set it to be a trigger. See this page http://unity3d.com/support/documentation/ScriptReference/Collider-isTrigger.html You can make a collider a trigger by checking the box in the inspector while the box collider is selected. Then in the on OnTriggerEnter function you can destroy the particle emitter, and play the sound.

var sound : AudioClip;
var emitter : ParticleEmitter
Function OnTriggerEnter
{
    sound.Play();
    if (emitter)
        emitter.emit = false;
}

Now in the inspector just drag your audio clip and emitter into the variable spaces.

You should also check out the tutorials page http://unity3d.com/support/resources/tutorials/ the FPS Tutorial and Lerp tutorial cover alot of topics.

more ▼

answered Mar 25 '10 at 01:04 PM

mcadieux gravatar image

mcadieux
52 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5086
x640

asked: Mar 25 '10 at 12:00 PM

Seen: 3384 times

Last Updated: Mar 25 '10 at 02:06 PM