x


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.

more ▼

asked Mar 15 '12 at 02:24 AM

ctechnoboy87 gravatar image

ctechnoboy87
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first

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?

more ▼

answered Nov 16 '12 at 04:35 AM

reganmusic gravatar image

reganmusic
1 2

(comments are locked)
10|3000 characters needed characters left

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!

more ▼

answered Mar 15 '12 at 02:35 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

Sorry about repost (new). OK 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.

Mar 17 '12 at 12:58 AM ctechnoboy87

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, determine 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.isKinematic = 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.

Mar 17 '12 at 05:28 AM syclamoth

Do I put this in function start, update, or neither. I changed if (/other is the player, determine 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.

Mar 19 '12 at 10:40 PM ctechnoboy87

What does compiler says?

Mar 19 '12 at 11:02 PM Dakwamine

Need to fix all compiler errors.

Mar 19 '12 at 11:09 PM ctechnoboy87
(comments are locked)
10|3000 characters needed characters left
Be the first one to answer this question
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:

x288
x160
x97
x32

asked: Mar 15 '12 at 02:24 AM

Seen: 623 times

Last Updated: Nov 16 '12 at 04:35 AM