Two newbie questions
by Nate Gertsch · in Torque Game Builder · 06/30/2009 (12:15 pm) · 3 replies
Hello everyone,
I recently downloaded TGB and I've been playing around with it for about a week now. I've found that it's an excellent tool though I did have a hard time finding the documentation. I've gone through the tutorials and I started work on my first project, a missile command type game. So far, I've found the tools easy to work with and torque script very easy to understand (my background is mainly C++) but I did have two questions that I was wondering if a more experienced torque programmer could help me out on.
1) In the first version of my game, I had it set up so that clicking on the screen created a defensive missile that flew to the click location and destroyed any incoming objects that it collided with. This worked fine but I wanted to change it so that the missile created an explosion effect and this effect destroyed any incoming objects that collided with it. I got the first part working but the second has eluded me even though I'm 99% certain I'm doing it correctly.
When my missile reaches the correct point, I call the explode function.
This creates the explosion effect (I'm using an placeholder explosion effect from one of the tutorials) and sets it so that it sends and receives collisions. My incoming objects then should trigger a collision when they run into the explosions. I've made sure that the incoming objects have both the receive and send collision flags on and callback enabled.
This seems like it should really work yet the incoming objects go right through the explosion effects without ever triggering the respawn function. The fact that it's so simple makes me think that I'm overlooking something obvious. I thought the explosion object might have been deleted before it could collide with anything but the animation still plays and if I set it on "cycle" it keeps on going forever. Is there a way to get particle effects to trigger a collision?
2) My second question is simpler. I made a simple pause button for my game that calls sceneWindow2D.getSceneGraph().setScenePause(true) which works perfectly fine for pausing the game. Unfortunately it also pauses the pause button and I can't click on it again to toggle the pause effect. In the tutorials, people bound the pause command to a key but I'd like to avoid that as I have the goal of porting this game to the iphone and there is no keyboard on the iphone. Is there a way to have a pause button that pauses everything except itself or another better way to go about this?
I recently downloaded TGB and I've been playing around with it for about a week now. I've found that it's an excellent tool though I did have a hard time finding the documentation. I've gone through the tutorials and I started work on my first project, a missile command type game. So far, I've found the tools easy to work with and torque script very easy to understand (my background is mainly C++) but I did have two questions that I was wondering if a more experienced torque programmer could help me out on.
1) In the first version of my game, I had it set up so that clicking on the screen created a defensive missile that flew to the click location and destroyed any incoming objects that it collided with. This worked fine but I wanted to change it so that the missile created an explosion effect and this effect destroyed any incoming objects that collided with it. I got the first part working but the second has eluded me even though I'm 99% certain I'm doing it correctly.
When my missile reaches the correct point, I call the explode function.
function Missile::explode(%this)
{
explosion = new t2dParticleEffect()
{
scenegraph = %this.scenegraph;
};
explosion.setCollisionActive( true, true );
explosion.loadEffect("~/data/particles/smaller_explosion.eff");
explosion.setEffectLifeMode("Kill", 1);
explosion.setPosition(%this.getPosition());
explosion.playEffect();
%this.safeDelete();
}This creates the explosion effect (I'm using an placeholder explosion effect from one of the tutorials) and sets it so that it sends and receives collisions. My incoming objects then should trigger a collision when they run into the explosions. I've made sure that the incoming objects have both the receive and send collision flags on and callback enabled.
function Incom::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
$score++;
ScoreText.text = "Score : " @ $score;
%srcObj.Respawn();
}This seems like it should really work yet the incoming objects go right through the explosion effects without ever triggering the respawn function. The fact that it's so simple makes me think that I'm overlooking something obvious. I thought the explosion object might have been deleted before it could collide with anything but the animation still plays and if I set it on "cycle" it keeps on going forever. Is there a way to get particle effects to trigger a collision?
2) My second question is simpler. I made a simple pause button for my game that calls sceneWindow2D.getSceneGraph().setScenePause(true) which works perfectly fine for pausing the game. Unfortunately it also pauses the pause button and I can't click on it again to toggle the pause effect. In the tutorials, people bound the pause command to a key but I'd like to avoid that as I have the goal of porting this game to the iphone and there is no keyboard on the iphone. Is there a way to have a pause button that pauses everything except itself or another better way to go about this?
#2
You can detect a particle collision using onParticleCollision, but it won't tell you which particle collided, where it was, or what it collided with.
07/01/2009 (1:34 pm)
Particle collisions don't fire off the collision events the way other collisions do. That's probably why they are able to have so many running around on the screen and keep the frame rate up.You can detect a particle collision using onParticleCollision, but it won't tell you which particle collided, where it was, or what it collided with.
#3
I'll post the code, just in case another newbie has the same issue.
07/01/2009 (2:15 pm)
Thanks for your answer, it was really helpful. After reading your message and learning that I can't use particle effects for collisions, I coded a quick work around. I put up an invisible t2dStaticImage behind the explosion and had that be the object which triggered collisions. To be honest, I'm not sure why I didn't do it this way in the first place once I started having difficulties. I'll post the code, just in case another newbie has the same issue.
function Missile::explode(%this)
{
%explosion = new t2dParticleEffect()
{
scenegraph = %this.scenegraph;
};
//Particle don't trigger collisions so we create an invisible image for the
//incoming objects to collide with.
%explosionCollision = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
};
%explosionCollision.setCollisionActive(true,true);
%explosionCollision.setSize(%explosion.getSize());
%explosionCollision.setPosition(%this.getPosition());
//Delete the collision image after a second.
//May have to adjust depending on the length of the effect.
%explosionCollision.schedule(1000, "safeDelete");
%explosion.loadEffect("~/data/particles/smaller_explosion.eff");
%explosion.setEffectLifeMode("Kill", 1);
%explosion.setPosition(%this.getPosition());
%explosion.playEffect();
%this.safeDelete();
}
Nate Gertsch
and everything worked fine. Sadly, I've been unable to discover a similar error in my explosion collision detection.