x


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);
    }
}
more ▼

asked Mar 18 '12 at 05:24 PM

missypooh gravatar image

missypooh
77 31 48 50

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.

Mar 18 '12 at 07:20 PM aldonaletto

yes. you are right, my worm has a mesh collider. Do i have to make any changes to the collision detection? And do i also have to add rigidbody to my player?

Mar 19 '12 at 01:07 AM missypooh
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 18 '12 at 07:35 PM

davedx gravatar image

davedx
138 1 1 3

my terrain have a terrain collider. can it work? or i have to change to use box collider?? So i also have to set the iS trigger?

Mar 19 '12 at 01:06 AM missypooh

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.

Mar 19 '12 at 06:58 AM davedx
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x5081

asked: Mar 18 '12 at 05:24 PM

Seen: 338 times

Last Updated: Mar 19 '12 at 06:58 AM