Add rigidbody to gameObject and it drop infinitely

Hi all, i would like to detect collision between the worm and my player. So if the player collide with the worm, it will fly away and deduct the BP. I have added rigidbody to my worm. And when i run my games, my worm drop infinitely out of the scene. Can i know why?? I am very sure that it is place properly on the terrain. So aren’t very sure why it will drop infinitely. Please help.

// Make all rigidbodies we touch fly upwards
function OnCollisionStay(collision : Collision) 
{
    // Check if the collider we hit has a rigidbody
    // Then apply the force
    if (collision.rigidbody) 
	{
        collision.rigidbody.AddForce (Vector3.up * 15);
    }
}

Check if the worm collider is set to trigger - with Is Trigger set, it will fall through the terrain. Another possibility: if the worm has a mesh collider, you must set Convex, or it will fall through the terrain.

1 Answer

1

Does your terrain have a collider component? It needs a collider for the physics engine to detect when a rigidbody has come into contact with it. Tip: if your terrain is flat, use a BoxCollider not a MeshCollider to save expensive computation.

Nope, you should be fine with a terrain collider. The problem might be with your worm's collider as aldonaletto mentioned. Try changing its collider to a box collider - they're the simplest kind of collider and will at least show you if it is a collider problem and not something else.