SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Lighting & Rendering, Dynamics & Effects, Texturing / Dynamics & Special Effects / How to check for collision with a particular object?
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 19-05-2008, 11:05 PM   #1
RaginRob
Registered User
 
Join Date: May 2008
Location: Europe (Germany)
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Thumbs up Solved: How to check for collision with a particular object?

Hi there,

I'm looking for a solution to this:

I want to create a moving vacuum cleaner with particles and fields. My scene contains a plane (the floor), a moving polygon bar that emits the dust particles and spreads them over the floor, and the "head" of the cleaner.

The dust particles "rain" down on the floor and collide with it (without resilience). Once the floor is full of particles, the cleaner starts moving along a motion path over the particles. The cleaner head has a parented newton field with a cube volume which sucks in the particles within the volume shape.

Up to this point everything works just fine. The problem is: I need the particles to die as soon as they are sucked in, otherwise they gather around the field and occasionally show up. So I thought it would be best to make the particles collide with the cleaner head and then let them die via the Collision Event Editor. The problem is, the particles now die as soon as they touch the floor as this also is a collision. How can I tell them to only die when they collide with the cleaner head geometry? Is there a way to check with wich object the particles actually collides?

[UPDATE]

I found a way to distinguish the collision object! Now I can check if the particle collides with the floor or any other object. See the simplified scene file here:

http://www.megaupload.com/?d=LLPGILIL

I wrote an expression that changes the color of the particle to red as soon as it collides with the cleaner head. It doesn't react when colliding with the floor. Now all I have to figure out is how to let the particle die instead of turning red? I've been playing around with lifespanPP but it didn't work so far. Here's the expression I use:

Code:
int $idx = particleShape1.collisionGeometryIndex;
if( $idx != -1 )
{
string $geoC[] = `listConnections particleShape1.collisionGeometry[$idx]`;
string $shape[] = `listConnections ( $geoC[0] + ".localGeometry" )`;
// print( $shape[0] + "\n");
if ($shape[0] == "Staubsauger")
{
particleShape1.rgbPP = <<1,0,0>>;
particleShape1.lifespanPP = -1;
}
}

Last edited by RaginRob : 20-05-2008 at 12:55 PM.
RaginRob is offline   Reply With Quote
Old 20-05-2008, 12:19 AM   #2
ragecgi
Super Moderator
 
ragecgi's Avatar
 
Join Date: Sep 2002
Location: Minnesota, USA
Posts: 3,709
Thanks: 0
Thanked 13 Times in 12 Posts
Default

Sadly no, not in one uncut shot without mel anyway that I know of.

However, after trying a setup like you described, before I pass along my solution, are you really tied to your story of the falling dust first?
Because if you could get rid of that one collision, then things MAY be easier for you if you MUST do this all in one shot.

I ask because I think you may need to do this using a simple editing technique called a "cutaway".

TRIAL AND ERROR:
The first thing I tried was setting up your situation as you have it now, with the exception of when the dust fell to the floor for the first collision, I setup an event that killed the particle dust, and IMMEDIATELY spawned new particles with a conserve of 0 so they appear to the camera as the same piece of dust.
Then I created ANOTHER collision event with a new name that was setup like you had it originally and that seemed to work ok........ sortof.

The SECOND thing that worked PERFECTLY was to not show the falling dust at all.
Simply emit the dust from the floor geometry as a surface emitter with a conserve of 0 and an initially high rate till the floor filled up with dust then I killed the rate.

Then all I had to do was use only ONE collision event with the vacum-head geo and the particles dissapeared like they were supposed to.
(see my Maya 8.5 Unl. attachment for this example)


Of all of this, I believe the BEST solution for you would be to use a cutaway.
This is simply what it sounds like:

One rendered sequence is of the dust falling.
One sequence is a super-quick 1-2 second cutaway of the vacum cleaner beauty shot.
Then, render a final sequence for the part with the vacum head moving & killing particles.

This way you only have to deal with one collision at a time.

Lemme know if ANY of this gibberish helped
Attached Files
File Type: mb vacum_demo.mb (71.3 KB, 57 views)
__________________
Israel "Izzy" Long
Motion and Title Design for Broadcast-Film-DS
izzylong.com
ragecgi is offline   Reply With Quote
Old 20-05-2008, 12:37 AM   #3
RaginRob
Registered User
 
Join Date: May 2008
Location: Europe (Germany)
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks for your quick response!

Your solution is an interesting approach. The reason I'm using a newton field is to accelerate the particles towards the head when it's approaching, like in real world. The idea is to actually see them get sucked in the cleaner head.

As I wrote in the updated post above, all I need is a way to make the particular particle (lol!) stop existing when the collision with the head occurs. I think there must be a kind of command that can be executed in the expression (exactly where I change the particle color to red at the moment) that makes the particle die.

In my first post I somehow missed the chance of adding an attachment with the scene file, so here it is again.

There must be a way =)
Attached Files
File Type: mb cleaner.mb (72.4 KB, 50 views)
RaginRob is offline   Reply With Quote
Old 20-05-2008, 02:05 AM   #4
ragecgi
Super Moderator
 
ragecgi's Avatar
 
Join Date: Sep 2002
Location: Minnesota, USA
Posts: 3,709
Thanks: 0
Thanked 13 Times in 12 Posts
Default

Sadly with longform expressions like that I am clueless, hehe, so I wouln't be the one to ask about that

Regarding your collision event, however, have you checked the event editor at the bottom of the dialog is a checkmark to "Kill" the particles rather than split or emit others?

Just making sure, as mine kept defaulting to split, so I had to check it twice before it took correctly
__________________
Israel "Izzy" Long
Motion and Title Design for Broadcast-Film-DS
izzylong.com
ragecgi is offline   Reply With Quote
Old 20-05-2008, 02:39 AM   #5
RaginRob
Registered User
 
Join Date: May 2008
Location: Europe (Germany)
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dynamics, especially expression driven, is also totally new to me. But hey, there's always one day when you have to jump into the cold water and get along with it - somehow :headbang:

If I could manually do what this kill checkbox does in the event editor, I'd be happy. Well, I'll keep searching. Perhaps there's one expression magician out there who stumbles over this thread one day.

For now I'll call it a day


greetings,
Rob
RaginRob is offline   Reply With Quote
Old 20-05-2008, 01:59 PM   #6
RaginRob
Registered User
 
Join Date: May 2008
Location: Europe (Germany)
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

It's done, there was just a little tweak to be done :attn: . So here's a little walkthrough for those who want to use it. Quite simple, but it's just to get the idea across:

Let's say you want to have particles raining down on two cubes. Particles that collide with cube 1 shall become red and bounce off the cube (and eventually collide with cube 2), cube 2 shall kill the particles once they collide with it.


- Create an emitter that lets the particles rain down (omni, gravity field)
- Create 2 (or more, it doesn't matter) poly cubes and place them under the emitter in a way that some particles collide with cube 1 and some with cube 2
- name the transform node (pcube1 not pcube1shape) to cube_A and the other one to cube_B
- Make the particles collide with both of them (Particles-->Make collide)
- Select the particleShape and add a per particle collisionGeometryIndex via Add Dynamics Attibutes-->General-->Particle-->collisionGeometryIndex
- Also add an rgbPP Attribute (Add Dynamics Attibutes-->Color-->Add per particle attribute)
- now create a runtime expression on the lifespanPP and rgbPP attribute:

Code:
int $index = particleShape1.collisionGeometryIndex;
if( $index != -1 )
{ 
	string $geoC[] = `listConnections particleShape1.collisionGeometry[$index]`;
	string $shape[] = `listConnections ( $geoC[0] + ".localGeometry" )`;
	
	if ($shape[0] == "cube_A") 
		{
		particleShape1.rgbPP = <<1,0,0>>;
		}
	if ($shape[0] == "cube_B") 
		{
		particleShape1.lifespanPP=0;
		}
}
Important!!! You have to set the lifespan mode to "lifespanPP only" under Attribute Editor --> particleShape1 --> Lifespan Attributes. It took me hours and buckets of coffee to notice that. Rob was raging again

You can easily add more collision objects with different effects on the particles, I think a switch-case condition would be more elegant for that.

I attached a scene file with the stuff above, have fun!
Attached Files
File Type: mb collisions.mb (59.9 KB, 93 views)

Last edited by RaginRob : 20-05-2008 at 02:03 PM.
RaginRob is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.