x


RigidBody Collision Detection

Hi,

I noticed a new feature with the Rigid Body component, 'Collision Detection'. I have it set to Continuous and it is unstable!

The code that I have is defined in my PlayerMoveScript C# file:

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "GameObject_1")
    {
        ON_TRIGGER = true;
    }
    else if (other.gameObject.tag == "GameObject_2")
    {
        ON_TRIGGER = true;
    }
    //....
 }

void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "GameObject_1")
    {
        ON_TRIGGER = false;
    }
    else if (other.gameObject.tag == "GameObject_2")
    {
        ON_TRIGGER = false;
    }
}

so I referece the ON_TRIGGER bool type in another script:

void Update()
{ 
    Debug.Log(PlayerMoveScript.ON_TRIGGER);
}

I get true, false, true, false, true, false when I am ON the game object and when the RigidBody->Collision Detection feature is set to Continuous, Discrete or Continuous Dynamic.

Is this a performance issue? It worked fine in 2.6.1 (without this additional feature)

The player has these components attached:

MeshRenderer (which really doesn't have anything to do with CD) RigidBody (with Collision detection to Discrete) Capsule Collider

The game object has these components attached:

MeshCollider MeshRenderer RigidBody (with CD to discrete)

is there a mismatch or something? The player has a child object "bodyMesh" with the same components.

more ▼

asked Sep 29, 2010 at 10:21 PM

lampshade gravatar image

lampshade
386 233 179 196

continuous and dynamic collision detection only works for sphere, box or capsule colliders. Also the object gets push away from the collision.

Sep 29, 2010 at 11:20 PM spinaljack

The player is colliding with a MeshCollider. The player is envelopped within a Box Collider. My guess is that their are a number of things that could be wrong, so let me post everything that is attached to the relevent game objects . . .

Sep 29, 2010 at 11:26 PM lampshade

You DON'T want to use continuous collision detection unless you are using very fast moving objects (fast enough to go from 1 side of the collider to the other within 1 frame i.e. passes through). The performance hit is rather substantial for continuous collision detection.

Sep 30, 2010 at 12:59 AM Peter G

How can I get my boolean varaible to stay true? It worked fine with 2.6.1

Sep 30, 2010 at 03:57 AM lampshade
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

When you use a rigidbody u need to consider to use FixedUpdate() rather than Update(), behaviour like the one you described can occur due to slight difference in the timing for the PhysX engine components.

It's all a very precisely tuned clock and when checking for collisions using Continous collision detection you are asking the machine to check a lot more, specifically usefull for checking FAST moving objects, but it costs a lot of effort, having to tune all the time would make for a lot of extra work so Unity3D assumes you want best performance with collision detection unless you need a more specific check for precise calculation (Which in my opinion is a wise decisions).

Unless the objects are going very fast don't use Continuous or ContinuousDynamic collision detection systems. And when using a rigidbody, use FixedUpdate wherever possible, even though I have to admit I am not always doing so myself, I'm not fully confident I understand what is going on when I do use it and I do not like that at all.

Also see the user manual references for more on this

FixedUpdate should be used instead of Update when dealing with Rigidbody.

From: Here_FixedUpdate

and:

Continuous Used for objects which the Continuous Dynamic detection needs to collide with.(This has a big impact on physics performance, leave it set to Discrete, if you don't have issues with collisions of fast objects).

Continuous Dynamic Used for fast moving objects.

From: Here_Continous

Hope it helps :)

I'm having some serious problems understanding just what is going on under the hood with all the collisions and who's calling what. The Unity3D actors are making it tricky for me. Used to doing all the work myself now it's gotta match the engine and components build that exists so it's quite easy to get lost in the maze.

Just keep backtracking and asking where it went wrong if you can't get out!

more ▼

answered Nov 10, 2010 at 09:31 AM

Proclyon gravatar image

Proclyon
1.5k 30 23 46

The problem, was that I had a MeshCollider attached to my game object. It needed to be a Box Collider.

Nov 15, 2010 at 10:35 PM lampshade

ok good to hear the problem is solved

Nov 16, 2010 at 07:55 AM Proclyon
(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:

x278
x42

asked: Sep 29, 2010 at 10:21 PM

Seen: 6326 times

Last Updated: Sep 29, 2010 at 11:54 PM