x


Making a particle emitter collide with a rigidbody object?

Hi,

I have a particle emitter that has a world particle collider attached to it, "send collision message" is enabled. I have a box with a mesh collider and rigidbody aswell as this script attached to it...

    function OnParticleCollision (other : GameObject)
{
    var body : Rigidbody = other.rigidbody;
    if (body) {
        var direction : Vector3 = other.transform.position - transform.position;
        direction = direction.normalized;
        body.AddForce (direction * 5);
    }
}

The particle is definitely hitting the box but its not moving the rigidbody what so ever. Any idea why this is?

Thanks.

more ▼

asked May 19 '12 at 12:46 AM

Lboy gravatar image

Lboy
36 8 13 18

@coolkid808 It might not be enough force to move your object, have you tried increasing the force value from 5 to something extreme like say...1000. If your player still does not move, there is another problem(unless your players mass is really high). Have you debugged from inside the function to ensure a collision is happening? Put a debug log or print inside of the conditional if(body){ } and see if it prints to the console.

May 19 '12 at 01:29 AM hijinxbassist

Thanks hijinx but i followed aldo's method and it fixed the problem

May 19 '12 at 11:17 PM Lboy
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

This script must be attached to the particle system, not to the rigidbody. If you want to add a script to the rigidbody instead, it should be:

function OnParticleCollision (other : GameObject){
    var direction : Vector3 = transform.position - other.transform.position;
    rigidbody.AddForce (direction.normalized * 5);
}

The main difference between both versions: in the first version (particle script), any rigidbody will be affected by this particle system; in the 2nd version (rigidbody script, like above), this rigidbody will be affected by any particle system that has World Particle Collider and Send Collision Message enabled.

more ▼

answered May 19 '12 at 06:12 PM

aldonaletto gravatar image

aldonaletto
41.2k 16 42 195

Thanks Aldo, I tried both methods, the first didnt seem to work, but when i attached the second script to the rigidbody as you suggested it worked perfectly. Thanks.

May 19 '12 at 11:16 PM Lboy
(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:

x1781
x636
x89
x54
x16

asked: May 19 '12 at 12:46 AM

Seen: 1174 times

Last Updated: May 19 '12 at 11:17 PM