Search Unity

Particles Collide Only Once

Discussion in 'Scripting' started by rand1815, Sep 29, 2009.

  1. rand1815

    rand1815

    Joined:
    Apr 7, 2009
    Posts:
    27
    Hello everyone, I have searched the forums and can't seem to find an answer to this problem even though I have read a couple of people that have mentioned it.
    I am trying to set up a particle system that will pop out a bunch of power ups (like candy out of a pinata.) The character can then run around and pick them up. The problem that I am running into is that once the items bounce along the ground or another collider they will no longer register any other collisions. At first I thought this was because the center of the particles were sitting flush with the ground and the character was running over them. But then I noticed that they are also sitting on top of trigger colliders that my character can run through, this means that my character is clearly hitting them with his character collider, but no message is being sent.
    My message code is just sending a Debug.Log("hit") and that indeed works if the character touches one of the particles before it hits the ground or something else. So it seems to me that once the particles are hitting the ground or another collider they they are no longer registering hits with my character!

    Has anyone else run into a problem like this?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    So, you're saying that once the particles are inside the trigger area, further collisions aren't registered? Is there any chance you could post the script you are using to catch the collisions?
     
  3. rand1815

    rand1815

    Joined:
    Apr 7, 2009
    Posts:
    27
    Yeah, the particles are actually berries that the player collects. Once the berries hit the ground or the trigger on the bush that they come from (which activates the particle emitter) It no longer registers when the player touches them. If the berries hit the player while they are in the air before touching anything else it does register. Here is the script that is on the emitter! Thanks!

    private var numOfBerries : int = 0;
    function OnParticleCollision (hit : GameObject){
    if(hit.tag == "player"){
    numOfBerries++;
    Debug.Log("you've hit "+numOfBerries+" berries");
    }else{
    Debug.Log("I hit something else");
    }
    }
     
  4. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    Are you just giving them a velocity or are you applying a force as well? I've noticed that when particles lose all their velocity they cease to call messages. However, if you give them a -y force that's strong enough, they'll still call messages due to continuing to attempt to move.

    Also, if you want them to ignore the trigger collider, put the trigger collider in a special layer and make the World Particle Collider ignore that layer.

    Just my thought.
     
  5. rand1815

    rand1815

    Joined:
    Apr 7, 2009
    Posts:
    27
    That did it! The particles were hitting the ground and stopping and that is why they weren't registering a hit. Interestingly the character collider still doesnt make contact when the particles are on the ground. I think this is because the bottom of the capsule touching the ground plane is just one point and the particles are just one point. By adding a box collider and moving it down lower than the character the hits will go through when the particles are on the ground.

    Now I just have to find a way to keep velocity on the particles but allow them to appear as if they have landed and stopped on the ground.

    Thanks a million!