Game Development Community

Assign Particle help

by AndyGFX · in Torque Game Engine · 09/06/2004 (12:48 pm) · 16 replies

How to I assign user defined particle to ShapeBase at user defined mount point, in example rocket gear fire/smoke (I need this for player ship model) ...

#1
09/06/2004 (1:32 pm)
Do you want to mount an emitter to the object? If you do, you need to make a new mount function that will attach an emitter to the specified node.
#2
09/06/2004 (9:12 pm)
OK, but this function need I make in script or in core engine?
#3
09/06/2004 (9:20 pm)
It needs to be a C++ function. I would add it to the shapebase class so you can mount emitters to any shapebase object.
#4
09/06/2004 (10:29 pm)
Here's a little trick I picked up from the GG forums: You can 'fake it' with an empty weapon.

Create a DTS object that contains no mesh data, just a mountpoint and muzzlepoint node. Assign it to a weapon image, and then configure it like so:

datablock ShapeBaseImageData(BuildingDustImage)
{
   shapeFile = "~/data/shapes/weapons/empty_weapon.dts";

   mountPoint = 3;
   className = "ParticleEmitterImage";

   stateName[0]                       = "Activate" ;
   stateEmitter[0]                    = "YourParticleEmitterDatablock" ;
   stateEmitterTime[0]                = 5000.0 ;
   stateTimeoutValue[0]               = 5000.6 ;

};

Now, when you want an object to emit some particles at mount3, you just do a mountimage, and bam. You can also do a scheduled unmountimage just to clean up things after the emitter has stopped.

It's hacky, and wastes a teeny bit of resources, but it will do in a pinch and requires zero engine code modification. A better way is to do as Josh says, make a new emitter that is handled by that particle shapebase class. (For an example, check out the footpuff emitters for a player object.)
#5
09/06/2004 (10:50 pm)
Wow. Thanks. Work it. :) For beggining it is good. I work at game prototype. If I need later, I will add this part to C++.
#6
09/07/2004 (7:26 am)
I have a similar problem that I would like to do without "faking" weapon mounts.

I'm building a Steam-Mecha game, where I want the joints of the mecha to leak a bit of steam more or less all the time.

I've got mount points on all major joints where the parts of the mecha is mounted ( so we can rip them off when they take enough damage ). But I cant use the expected
%player.mountObject(%smoke, 10);
from script as the class ParticleEmitter is not inheriting from ShapeBase :(

So Josh: How would I go about adding the
Quote:new mount function that will attach an emitter to the specified node
?

Thanx
/Bjarne

PS: My mecha is a Player class, not a Vehicle.
#7
09/07/2004 (10:36 am)
I had some problem. :) Try set mountPoint = 10; inside datablock not in %player.mountObject(%smoke, 10); then work's.

PS: Second parametr is NODE ID not MountPoint ID !!!
#8
09/07/2004 (9:55 pm)
I have mounting emitters on my to-do-in-a-while list for a side project so I haven't really looked into it. You would need to add mount functionality to the particle node object, and the particles will just emit from it. It sounds simple enough, but I haven't looked into how the object mounting works. I need this fuinctionality for melee weapon charge effects around my players hands, so I'm willing to help you out with it.

After scanning through the ShapeBase class, I looks like the mounting functionality needs to be ported to the particle node class. This would be a great resource, or even a patch. I'll look into it more tomorrow.
#9
09/07/2004 (11:07 pm)
Cool, I'll be looking into it as well, because I really need this for the demo. ( bells and whistles are of high priority right now :) )
#10
09/08/2004 (11:38 am)
I fixed it, and I wrote a tutorial on how I did it, hope that helps you guys as well.

www.garagegames.com/images/uploaded/imag.8933.first_steaming_mech.jpg
#11
09/08/2004 (3:52 pm)
Glad to see that you got it working. Its not what I'll be adding, but its cool.
#12
09/09/2004 (12:40 am)
The solution I did does not give the possibility to attach emitters to mounts, it just makes it possible to attach them at a pre-set offset from the Player center.

So my solution will not be a good one of you would like an emitter to be bound to a mount that is moved during animation cycles ( Like a glow around a hand doing magic while walking or something like that ).

I guess that is what you want to do Josh? That would kick my relatively simple solutions ass :)
#13
10/26/2004 (6:36 pm)
This is exactly what I am wanting to do.. to attach a particle emitter to the players hand. So far all the stuff I've tried hasn't worked.
I can attach things like weapons and such to mount points in code, but not in script.

%position = %player.getTransform();
doesnt work as the emitter always ends up at the player's feet.

%position = %player.getMuzzlePoint(0);
does pretty much the same thing.

I have the player's right hand as mountPoint 0 and his left as mountPoint 1.

For a projectile spell effect, I use
%p = new Projectile()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %position;
sourceObject = %player;
sourceSlot = 0;
client = %player.client;
};

but the sourceSlot doesn't seem to do anything.

And obviously %position = %player.getMountTransform(0);
doesn't work since this isnt accessible from script and returns a matrix, not a vector, as far as I can tell.

So the question remains.. How can I get the position of a mountpoint on the player in script?
#14
10/26/2004 (7:17 pm)
Well I've been searching for about a week as to how to get the position of a mountpoint. As it turns out, I finally made the above post and whatta know, I find a post totally randomly and it solves my problem...

Josh "The_Force" Moore
Member Posted: May 24, 2004 14:26 CDT

This should work.

%seatPos = getWords(%vehicle.getSlotTransform(%node), 0, 2);


I changed it to suit my purposes...

%position = getWords(%player.getSlotTransform(1), 0, 2);

This gives me the position of slot 1 on my player, which I use to cast projectile type spells from. Hurray!
#15
10/26/2004 (10:15 pm)
Thats a nice one Chuck.

And by the way: We had some crashes caused by the damage emitter implementation in our project. It turned out that if you add damage emitters to the AI, you also need to set up damage emitters in all AI characters... whe forgot to add it to one type of AI and got really strange craches.
#16
03/17/2008 (4:29 am)
Hey guys...

For what it's worth to anyone, I am sharing what has worked well for me to be able to mount a particle emitter directly to a player model. The following quote from David Grace inspired me:

Quote:A better way is to do as Josh says, make a new emitter that is handled by that particle shapebase class.

Here is the implementation:

A.) Look for all references within player.h and player.cc of "footPuff" whatever... above it, add your own duplicate of the code that suits your needs (in my case, a jetpack emitter)...

Then, when you are ready to actually start up the emitter, you hit code that is roughly like this (but keep in mind that this is my jetpack emitter code... it will have to be adjusted for what you are doing):

ParticleEmitter * jetEmitter = new ParticleEmitter;
jetEmitter->onNewDataBlock( mDataBlock->jetpackEmitter );
MatrixF mount7Matrix;
this->getRenderMountTransform( 7, &mount7Matrix );

// New emitter every time for visibility reasons
ParticleEmitter * jetEmitter = new ParticleEmitter;
jetEmitter->onNewDataBlock( mDataBlock->jetpackEmitter );
MatrixF mount7Matrix;
this->getRenderMountTransform( 7, &mount7Matrix );
Point3F& pos = mount7Matrix.getPosition();

if( !jetEmitter->registerObject() )
{
   Con::warnf( ConsoleLogEntry::General, "Could not register jetEmitter for particle of class: %s", mDataBlock->getName() );
   delete jetEmitter;
   jetEmitter = NULL;
}
else
{
   jetEmitter->emitParticles( pos, Point3F( 0.0f, 0.0f, 1.0f ), mDataBlock->jetpackRadius,
   Point3F(0.0f, 0.0f, 0.0f), mDataBlock->jetpackNumParts );
   jetEmitter->deleteWhenEmpty();
}

I hardcoded the particles to come from "mount7" on my model, but you might want to work this differently depending on your needs. Hope this helps!!!