How make activate a Rigid body after object moves off an object?

How do you make a cube fall after you move a box on it then off it. So its there when you walk on it but when you walk off it falls doawn.

2 Answers

2

There are a few ways, but the simplest one (the one I'd go for) would be to link a trigger volume on top of it, something like this:

First, make your rigidbody block, nice and simple. Set it to 'kinematic' so that it doesn't just fall straight away.

Then, make an invisible, trigger collider that sits above it, and add something similar to the following script:

public Rigidbody linkedBlock;

void OnTriggerExit(Collider other)
{
    if(/*other is the player, determine this however you like- */ true)
    {
        // Make the block fall!
        linkedBlock.isKinematic = false;
        // makes sure it only works once
        gameObject.active = false;
    }
}

Then, make sure that you assign the correct block to the 'LinkedBlock' property, and set up some system for determining which object the player is, and you're set to go!

What does compiler says?

That's not very helpful ... Double click on your console and it will give you the actual compiler errors. :P

Hi, this works for me, but i have a problem where there are a bunch of rigid bodies flying around my scene and the trigger activates when ANY of them pass through the trigger box. I only want the trigger to work when my player passes through the box. Which word do I need to replace with my game object "testChar"? I'm using the Java one.

I have many “Collider” in my scene that are likely to pass through my trigger box, but I only want my player to set off the trigger box, is “Collider” the word that I need to be replacing in this script? If so… what with?