Destroy Enemy Rigidbody after Jumping on Head?

I’m making a 2.5D platformer, and before, I had everything working great, except the enemies had no physics at all. So I added a rigidbody to them so they could stand and move on the same platforms I’m on. What I want to do though, is make it so that when I kill the enemy, the rigidbody will disappear so its body can fall off the screen. I feel like I’ve gotten close SO many times, but I’ve screwed around with the code so much, I give up on finding the fix by myself. How do I fix what I have broken? I would also like to know how to flip the enemy’s texture depending on the direction he’s facing, if anyone can look at that part of the code and give me pointers. The method I tried didn’t work. My enemy is a textured quad with a box collider and my player is a textured plane with a modified first person controller, both rotated to face the camera, and locked on the Z axis. They are tagged “Enemy” and “Player” respectively. They have prefabs, especially so there can be duplicates of the enemy on the screen.

#pragma strict
private var fall : boolean;
var Player : GameObject;
var spawnPoint : PlayerRespawn;
var stomp : boolean;
var stompc : AudioClip;
var X : float;
var rbdy : GameObject;

function Start () {
var spawnPoint = Player.GetComponent("PlayerRespawn");
//var enemy = Enemy.getComponent(Rigidbody);
X = transform.localScale.x;
var rbdy = GameObject.Find("Skater Kid 1").GetComponent(Rigidbody);
}

function Update () {
if(stomp){
//if(collision.rigidbody){
//Destroy(enemy.GetComponent(Rigidbody));
//}
transform.position.z = 4;
transform.localScale.y /= 2;
fall = true;
gameObject.GetComponent(PlatformMovement).step = 0.0;
stomp = false;
}
if(rigidbody.velocity .magnitude  > 0){
transform.localScale.x = X;
}
if(rigidbody.velocity .magnitude  < 0){
transform.localScale.x = -X;
}
if(fall){
transform.position.y -= 0.05;
}
if(transform.position.y < -25){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider){
if(stomp){
if(rbdy.CompareTag ("Enemy")){
rbdy.Destroy(rbdy.rigidbody);
}
if(!stomp){
if(other.tag == "Player"){
spawnPoint.death = true;

//var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
//var sf = Camera.main.GetComponent(smoothfollow2);
//sf.target = P.transform;
}
}
}
}

Why not disable it instead of destroying it?

this.GetComponent<Rigidbody>().enabled = false;

I solved it by putting “rigidbody.detectCollisions” in the top of the update function and making small adjustments to the rest of the code.
Here’s what I changed in “function.start”:

var rbdy = GameObject.FindGameObjectsWithTag("Enemy");

And here’s the rest of the code.

if(stomp){
//if(other.tag == "Player"){
rbdy.rigidbody.detectCollisions = false;
//}
transform.position.z = 4;
transform.localScale.y /= 2;
fall = true;
gameObject.GetComponent(PlatformMovement).step = 0.0;
stomp = false;
}
if(rigidbody.velocity .magnitude  > 0){
transform.localScale.x = X;
}
if(rigidbody.velocity .magnitude  < 0){
transform.localScale.x = -X;
}
if(fall){
transform.position.y -= 0.05;
}
if(transform.position.y < -25){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider){
if(!stomp){
if(other.tag == "Player"){
spawnPoint.death = true;
}

Make a different GameObject and merge it with the Player. Place it in the bottom. Name it feet and drag this Script(JavaScript) on the enemy :-
Don’t forget to add pragma strict to the script


function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == “feet”)
{
Destroy(gameObject);
}
}_________________________________________________________________________________________________