- Home /
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.
Answer by syclamoth · Mar 15, 2012 at 02:35 AM
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!
Sorry about repost (new). O$$anonymous$$ im slightly confused on what i need to change in code. I made linkedblock;Platform which is what i want to fall and everything else im confused on. Cube is player that moves around, Trigger is the trigger, and Platform is what needs to fall.
Oh, you're working in JavaScript? Why? Also, you should have told me.
Seriously, this is working code here. Just make the Platform a rigidbody, so that it can fall (otherwise it won't ever fall without special code), and make sure that the player can trigger triggers (needs to have at least one rigidbody involved).
Here's a javascript version, if you want:
var linkedBlock : Rigidbody; // Assign this in the editor
function OnTriggerExit(other : Collider)
{
if(/*other is the player, deter$$anonymous$$e this however you like- */ true)
{
// this section has to be activated by some conditional that makes sure that
// it's the player, not something else.
linkedBlock.is$$anonymous$$inematic = false;
gameObject.active = false;
}
}
Put that script on a trigger, and then drag the platform onto the slot exposed in the inspector. I'm really not sure how much more clear I can make this.
Do I put this in function start, update, or neither. I changed if (/other is the player, deter$$anonymous$$e this however you like- / true) to if (gameobject.Cube = true) not sure if I did that right and when I try to run it, it says compiler errors.
Answer by reganmusic · Nov 16, 2012 at 04:35 AM
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220613065131im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How make an object fall after a cube moves off the object? 1 Answer
3D Cubes vibrating and sliding while ontop of eachother 0 Answers
Falling off respawn 4 Answers
Falling Objects Sound 1 Answer
Respawn after falling off script? 2 Answers