OnTriggerEnter, Destroy a script

Hi,

I’m starting a new thread, because I didn’t have any luck on my last one. Below, is my script for destroying a script after 2 objects enter a trigger. I haven’t had any luck so far…

function OnTriggerEnter(other : Collider)
{
// Destroy the script
Destroy(other.gameObject.GetComponent(MovementControl));

if (other.attachedRigidbody) {

//setting rigidbody gravity boolean to true
other.attachedRigidbody.useGravity = true;
}
}

So, this is what I want to have happen:

-“Cube A” has a rigidbody and a script called “MovementControl” attached so the player can move it.
-“Cube B” has the “is Trigger” enabled and the script above attached to it.

“Cube A” is supposed to collide with “Cube B” and after doing so, the “MovementControl” script attached to “Cube A” should be destroyed and it should come to a stop on top of “Cube B”. Instead of stopping, “Cube A” passes directly through “Cube B” and losses the “MovementControl” script when it collides with other objects that don’t have the “is Trigger” enabled. When I disable the “is Trigger” on “Cube B”, the “MovementControl” script is destroyed when the 2 cubes come in contact, which is strange to me, but I’m brand new to this stuff. Can someone please help?

Thanks in advance for your help.

Can somebody please shed some light here? I’m super lost and I’m sure it’s an easy fix…

OOOPPS!! The script has been fine the whole time!! The problem is that I wanted “Cube A” to stop on top of “Cube B”, but instead, it enter into the collision, which is “Cube B”'s mesh I’m guessing and loses it’s MovementControl and Rigidbody gravity thereafter and lands on the object below. I thought the object below is what was stopping “Cube A”.

Looks like I will have to make an invisible object with “isTrigger” enabled just above “Cube B”, that way “Cube A” will lose the script and gain the gravity before it enters "Cube B"s mesh and hopefully it will stop… I’m sure it will!!

got the same problem bro. what did you do to fix this problem?

I ended up adding a second collider to Cube B (now it has a box collider and a mesh collider). The box collider has the isTrigger enabled and I made it slightly larger than the mesh. So now Cube A enters the trigger before hitting the mesh and therefore collides with the mesh of Cube B. hope that helps.