Game Development Community

OnParticleCollision()

by Tyler Slabinski · in Torque Game Builder · 02/10/2008 (11:52 am) · 4 replies

Ok, I have something on my game that is going to act as a flamethrower, so right now I have this:

%flameThrower = new t2dParticleEffect() { scenegraph = myScenegraph; };
%flameThrower.loadEffect( "flameThrower.eff" );
%flameThrower.setEffectCollisionStatus(true);

function onParticleCollision( %flameThrower )
{
};

Now I want to make it so that when it comes in contact with an enemy, each particle would inflict 1 damage. So does anyone know what I would do? I am not very good with collisions.

#1
02/10/2008 (12:06 pm)
Tyler, it looks to me as if a scene object recieves the collision as well. It appears that the "onParticleCollision" callback just notifies you that a particle collided so you can manipulate it, but the receiving object deals with the collision themself.

function myClass::onCollision(...)
{
   if (%srcObject.getClassName() $= "t2dParticleEffect" && %srcObject.effectFile $= "flameThrower.eff")
      %dstObject.resolveFlamethrowerContact();
}
#2
02/11/2008 (12:39 pm)
So lemme get this straight, I need to have the object call the server to find out what hit it(%scrObject.getClassname())

Then if the collided object is flameThrower ($= "t2dParticleEffect" && %srcObject.effectFile $= "flameThrower.eff") it activates the function resolveFlamethrowerContact(); for %dst.object.

Is that correct?
#3
06/09/2008 (11:35 pm)
That sounds about right Tyler, except part of what they did with particle collisions I'm not sure it actualy sends collision callbacks to other objects.If i'm wrong I hope someone can help us find out how do do it . I'm working on a similar project as for now I created an invisible object that flags objects under it when the onParticleCollision callback is triggered.
#4
06/12/2008 (1:31 pm)
Just to add to that: When I developed the particle engine they didn't originally have any collision detection. Eventually though, under the weight of many requests, I added the feature but the reason why I originally put up so much friction is still there, they're damn expensive things to activate.

If you can treat the particles as cosmetic and have invisible object(s) like t2dSceneObjects doing the actually collision detection, maybe even picking like pickRect then you'll nearly always get better performance.

Of course I'm assuming you're using lots of particles. Several dozen particles won't be a problem but always, every particle checks for collisions and if you have huundred(s) then you're making the CPU work for it's living.

It's just a cautionary post that's all.

Melv.