Game Development Community

SrcObj vs %dstObj and mounting an explosion effect.

by Jon Mitchell · in Torque Game Builder · 12/30/2006 (2:34 pm) · 15 replies

So today I find that I am scratching my head over this function's behaivor. While I have the mount point at the %srcObj no explosion happens when the collision occurs, an echo verifies that the collision is registered, if I change it to the %dstObj an explosion will happen, but of course in the middle of the other object and not at the point of impact where the projectile hits.
%srcObj and %dstObj are basically more or less the same are they not? they are just a pair of location points on the screen, why would the particle effect mount on one but not the other?

function playerCannon::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
   if(%dstObj.class $= "terrain")
   {
   %srcObj.safeDelete();
   %shellExplode = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
   %shellExplode.mount(%srcObj, "0,0", 0, false);
   %shellExplode.loadEffect("~/data/particles/customExplosion.eff");
   %shellExplode.setEffectLifeMode( kill, 5 ); 
	 %shellExplode.playEffect();
   }
}

#1
12/30/2006 (9:26 pm)
Maybe try moving the %srcObj.safeDelete() to the end of your function. It appears you are deleting this object and then trying to mount effect on it.
#2
12/30/2006 (9:49 pm)
Hi Stanley,
I just tried moving the safe delete command to the end after play effect and unfortunately it had no change on the effect.
#3
12/30/2006 (10:41 pm)
Try removing the quotes from "0,0"

Like this:
%shellExplode.mount(%srcObj, 0,0, 0, false);
#4
12/30/2006 (11:28 pm)
There was no change, but it did not kick out any errors either.
#5
12/31/2006 (1:13 am)
%srcObj and %dstObj are not pairs of points on the screen. They are actual objects. If you just want the explosion to happen where the object is then don't worry about mounting it. Just set the position to the position of the object that exploded. In general you won't want to delete the object before you're done using it. If you want to pass "0,0" as a pair like that you have to remove the comma and just pass "0 0"
#6
12/31/2006 (8:43 am)
Thanks for the clairfication Ben.
I do want to mount the explosion on the %srcObj which is a projectile, in this case the %dstObj is a non-destructable wall and it is a large object, having the explosion on it looks kind of funny and from an asthetics view it would look nicer to have the explostion at the point of contact. Destroyable objects I do have them with their own class so when the projectile touches them they do their own exploding and not the projectile.
#7
12/31/2006 (9:41 am)
Check to make sure the layer that the %srcObj resides is under the explosion. You should be able to set the layer on the effect using the setLayer method. My thinking here is that maybe the %srcObj is covering up the explosion. Just a thought.
#8
12/31/2006 (10:45 am)
I set my effect to layer 0, the %dstObj to layer 3 and the projectile to level 5 and no luck there either, I thought for sure that would be the problem since it made a lot of sense. :)

This is what the code looks like now with the delete and set layer in it.

function playerCannon::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
   if(%dstObj.class $= "terrain")
   {
   %shellExplode = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
   %shellExplode.mount(%srcObj, "0 0", 0, false);
   %shellExplode.loadEffect("~/data/particles/customExplosion.eff");
   %shellExplode.setEffectLifeMode( kill, 5 ); 
	 %shellExplode.setLayer(0);
	 %shellExplode.playEffect();
   %srcObj.safeDelete();
   }
}
#9
12/31/2006 (11:31 am)
Lets see if this works without the mounting for now. Comment out the mount statement and insert the following code

%shellexplode.setPositionX(%srcObj.getPositionX())
%shellexplode.setPositionY(%srcObj.getPositionY())
#10
12/31/2006 (11:58 am)
Very odd, I did as you suggested and the explosion does show up now, but in the middle of the screen.
I did an echo to get values of %srcObj.getPositionX and %srcObj.getPositionY and they are returning values but the position is not getting set for the exlosion.
I also tried changing it a little by doing this:
$srcY = %srcObj.getPositionY();
   $srcX = %srcObj.getPositionX();
   %shellExplode.setPosition($srcX, $srcY);

To see if there would be any change, but the explosion still happened in the middle of the screen.
#11
01/03/2007 (9:22 am)
I am stumped and this making little sense to me, even when setting the position manually then testing it, the effect still appears in the middle of the screen?! Here is the code as it looks like right now.

function playerCannon::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
   if(%dstObj.class $= "terrain")
   {
   %shellExplode = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
  $srcY = %srcObj.getPositionY();
  $srcX = %srcObj.getPositionX();
  %shellExplode.loadEffect("~/data/particles/customExplosion.eff");
  %shellExplode.setPosition(-53 -110);  //would normally use $srcX and $srcY
  %shellExplode.setEffectLifeMode( kill, 5 ); 
  %shellExplode.setLayer(0);
  %shellExplode.playEffect();
  %srcObj.safeDelete();
   }
}
#12
01/03/2007 (9:24 am)
Try using one of the stock particle effects that comes with TGB and see if you get different results. It could be something with your customExplosion.eff settings that is causing this.
#13
01/03/2007 (10:30 am)
Ah ha!
While I was chaning the effect as you suggested Stanley I happened to change the location of the setPosition in the order of the line in the function and kapow! At least that is the sound effect in my head when there is explosion :-) So I changed the numbers back to srcX and srcY and it works like a charm now!
I moved the setPosition and put it below the line where the actual .eff file is loaded.


so it looks like this
%shellExplode = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
  %shellExplode.loadEffect("~/data/particles/customExplosion.eff");
  %shellexplode.setPositionX(%srcObj.getPositionX());  // these lines used to be before the loadEffect
  %shellexplode.setPositionY(%srcObj.getPositionY()); //  once below it worked!
  %shellExplode.setEffectLifeMode( kill, 5 ); 
  %shellExplode.setLayer(0);
  %shellExplode.playEffect();
  %srcObj.safeDelete();


Thank you again for the help!
#14
01/03/2007 (11:40 am)
Glad you got it working. You could simplify your code a bit by trying (just in case you weren't aware of these overloads)

%shellExplode.setPosition(%srcObj.getPosition());
#15
01/03/2007 (12:37 pm)
I did not know that Ben, and the less code the happer I am :D