No Hit after Grounded

I am working on a game where my foes lob objects at my character. Right now when they hit the character with something the character dies, that's fine.

I'd like though for the object to just sit on the ground if the lobbed thing misses my character, and then the character can pick them up and have a different result.

I'm not quite sure how to make this work so I have tried this but I get an error.

I'm wondering if someone can take a look and help me solve this?

thanks

Daev

EDIT---

I updated my script to be thus below and added it to my object being thrown. With trigger set on on my object this hits my character and he loses a life, however because it is a trigger object it doesn't sit on the ground, just keeps going.

I'm not sure what I'm doing wrong here... when I turn the trigger off on the Mesh Collider it sits on the ground but has no affect on the character, nor does it disappear if I collide with it.

-Daev addendum

var goodSound     : AudioClip ;
var badSound      : AudioClip ; 

static var hitGroundYet : boolean = false ; 

@script AddComponentMenu("BADDIE/Litter Hit")   

function OnLitterCollider(collisionInfo : Collider) 
{
    if (collisionInfo.gameObject.tag == "GROUND" )
        {
        var hitGroundYet : boolean = true ;
        }

    if (collisionInfo.gameObject.tag == "CHARACTER" )
    {

        if ( hitGroundYet == true )
        {
            audio.PlayOneShot(goodSound);
            Destroy(collisionInfo.gameObject);

        }
        else
        {
            audio.PlayOneShot(badSound);
            Destroy(collisionInfo.gameObject);
            lives.lives--;
        }

    }   
}

isGrounded is only a function of the characterController and the wheel collider so if the object you hit is not one it will trow an exception.

Edit: I wrote this kind of confusingly. IsGrounded() is not a function of gameObjects so you have to access another component.

Just check if your object hit the ground or not (using a layer or a tag), and if it did, then you can do various things to "freeze" it in place... you could disable gravity or make the rigidbody kinematic, or write your own component script to "Freeze" the object in place. You don't need to use "isGrounded", just see if your flying object collided with the ground or not.

Re: Your Comment

The trigger just determines whether physics collisions occur or not. If you set it to true, things will pass through each other. If you set it to false, things will literally "collide" and bounce off of each other.

I'm assuming the ground is some sort of terrain or something? Be sure that the ground has the tag "TRIGGER_OFF", as this example uses that.

Start by attaching this script to your projectile. Set Trigger to OFF.


// C#
void OnCollisionEnter(Collision other)
{
     if(other.gameObject.tag == "TRIGGER_OFF")
     {
          collider.isTrigger = true;
     }
}

void OnTriggerEnter(Collider other)
{
     if(other.gameObject.tag == "CHARACTER")
     {
          // Player picked up the object while it was resting on the ground.
     }
}