PDA

View Full Version : query rigid body collision


misterwolfy
09-29-2010, 06:59 AM
How do I query whether a rigid body collision has occurred? Say I want to trigger an event when a cube hits a plane. Which MEL command would I use?

Another question: I suppose I would query at every frame and wait for the result to be True or 1 then trigger the event. But will the collision always occur on a frame?

Thanks for reading!

nessus
10-01-2010, 10:07 PM
How do I query whether a rigid body collision has occurred? Say I want to trigger an event when a cube hits a plane. Which MEL command would I use?

Another question: I suppose I would query at every frame and wait for the result to be True or 1 then trigger the event. But will the collision always occur on a frame?

Thanks for reading!

I was looking for the same thing the other day too, its one of the rigidBody node attributes:
rigidBody.contactCount and rigidBody.contactName.

misterwolfy
10-02-2010, 05:39 AM
Thanks! Yes I think that works. I was able to find this tutorial, which explains a way to detect when a collision happens, based on the collisionCount.

http://www.kolve.com/mt_rbCollisionDetection/rbCollisionDetection.htm (http://www.kolve.com/mt_rbCollisionDetection/rbCollisionDetection.htm)

I'd love to see other solutions, if anyone can provide code or tutorial links.

misterwolfy
10-03-2010, 06:51 AM
I got a decent result from this collision detection expression, linked above.

What I am trying to do is create a shader that "lights up" when a dynamic object collides with another.

http://www.youtube.com/watch?v=cpF_4JeHygY

The only problem is that when the object is at rest, it is still colliding with the other surface, so the texture animated incandescence loops.

The collision detection expression. I'm using a locator to store the attributes as suggested by the tutorial linked in my last post:

rb1ContactData.EXPR =0;

// variables
string $myRigidBody = "rigidBody83";
int $contactCount;
int $uniqueContactCount;
string $contactName2[];

// get $contactCount
$contactCount = `getAttr($myRigidBody+".contactCount")`;

// compute $uniqueContactCount
if ($contactCount > 0)
{
string $array[] = `rigidBody -q -contactName $myRigidBody`;
string $flatArray[] = flattenStringArray($array);
$uniqueContactCount = size($flatArray);
}
else
{
$uniqueContactCount = 0;
}

// set interface attributes
rb1ContactData.contactCount = $contactCount;
rb1ContactData.uniqueContactCount = $uniqueContactCount;


The shader incandescence expression:

int $theTime = `currentTime -query`;
if( $theTime == 0 )
lambert2.incandescenceR = 0;

if ( rb1ContactData.uniqueContactCount >=1)
if (lambert2.incandescenceR <.05)
lambert2.incandescenceR = 1;

if (lambert2.incandescenceR >.05)
lambert2.incandescenceR = lambert2.incandescenceR -.1;
else lambert2.incandescenceR = 0;

CGTalk Moderation
10-03-2010, 06:51 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.