Particle Attachment for AI

From The DarkMod Wiki
Revision as of 03:40, 10 June 2007 by Baddcog (talk | contribs)
Jump to navigationJump to search

Attaching Particles to an AI

Fairly easy to attach particles to an AI once someone looks into the SDK for you :D

The particle will be attached to a bone, this gives you plenty of options as most AI has 20+ bones. The names of the bones can be found in the AI's md5 file which can be opened with notepad or wordpad. ie: pagan_female_mesh.md5mesh , usually the joint names are fairly obvious as the animators need to find that info easily. left_hand is obviously a bone in the left hand.

You'll need to create a particle effect. Once you have that you can add some info to your AI's def file. It's probably best if you want to add a fire particle to a pagan females hand that you copy her .def file and give it a new name, this way the pagan_female files won't get messed up.

There are probably 2 ways to go with the particle attachment: 1-constantly emitted particle 2-particle emitted at intervals.

Adding this line to your AI's entity def description will add a particle (bc_sparx) to the joint named smokestack.

"smokeParticleSystem1" "bc_sparx-smokestack"

Alternately you can add the particle named smokestack to the joint named smokestack by using this line

"smokeParticleSystem1" "smokestack"

The first option is probably best as you can reuse particles instead of making a new one to match the joint name.

   anim walk		 models/md5/chars/steambots/lant_bot_searc.md5anim

{ frame 12 footstep frame 31 footstep

   	   frame 31     triggerSmokeParticle smokestack

}

This calls for some investigation. To the SDK!

[...a little while later...]

Yes, spawnargs starting with "smokeParticleSystem" (so that includes smokeParticleSystem, smokeParticleSystem1, smokeParticleSystemBobsYourUncle, etc.) are indeed referenced in the SDK. This is the relevant SDK function (it's called with keyName equal to "smokeParticleSystem"):


CODE /*

=========

idAI::SpawnParticles

=========
  • /

void idAI::SpawnParticles( const char *keyName ) {

   const idKeyValue *kv = spawnArgs.MatchPrefix( keyName, NULL );
   while ( kv ) {
       particleEmitter_t pe;
       idStr particleName = kv->GetValue();
       if ( particleName.Length() ) {
           idStr jointName = kv->GetValue();
           int dash = jointName.Find('-');
           if ( dash > 0 ) {
               particleName = particleName.Left( dash );
               jointName = jointName.Right( jointName.Length() - dash - 1 );
           }
           SpawnParticlesOnJoint( pe, particleName, jointName );
           particles.Append( pe );
       }
       kv = spawnArgs.MatchPrefix( keyName, kv );
   }

}


That's probably Greek to you if you've never seen C++ before... So I'll explain it. Basically what it's doing is looking for a dash (-) in the value of the spawnarg. Everything left of the dash is the name of the particle. Everything to the right of the dash is the name of the joint (for our purposes, a joint just means a bone). If there's no dash, then the particle name is the same as the joint name - this is probably what's happening in your case. It's finding the bone named "smokestack", but it's also looking for a particle named "smokestack". Since it doesn't find such a particle, you get black squares.

So if you want a particle called myawesomeparticle to be (permanently!) emitted from the bone smokestack, you might use the following spawnarg:

"smokeParticleSystem1" "myawesomeparticle-smokestack"

So far so good, but it's not active yet (I think - you might want to test this yourself to be sure). So you need to use the triggerSmokeParticle frame command to turn it on. As you've discovered, this is placed within an "anim" block and takes this format:

frame [framenumber] [bonename]

Where [framenumber] is the frame number of the animation, and [bonename] is the name of the bone/joint on which to trigger particle effects. Note that all particle effects on that bone will be triggered, if you have more than one.