Game Development Community

Mod the shoot Behavior

by Steven Smith · in Torque Game Builder · 07/02/2009 (12:54 am) · 1 replies

Is there a way to modify the shoot behavior to shoot one projectile at a time?
Here is what I'm trying to do: the gun shoots a ball....the ball bounces around the screen...and falls out of screen view...then and only then I can fire another ball. no matter how many times I hit the space bar (or any key I tie to shooting) I can't fire another ball wile the first ball is in play. THINK PIN BALL

any ideas? thanks

#1
07/04/2009 (2:10 pm)
If you're deleting the ball when it drops down then you can check for whether or not it is an object before you allow the projectile to be cloned. The ShootsBehavior::fire method actually already does a test like this (by ensuring that the %this.projectile exists). You just need to apply this test to the object you have previously cloned.

The trick is that you have to save the handle to the projectile that gets created with cloneWithBehaviors(). Right now it's just a local variable that's being tossed away when the ShootsBehavior::fire method ends.

So you might do something like this:

if(!isObject(%this.ball))
   {
      %this.ball = %this.projectile.cloneWithBehaviors();
      %this.ball.setPosition(%this.owner.position);
      %this.ball.setRotation(%this.owner.rotation);
      %this.ball.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
      
      if (!isEventPending(%this.fireSchedule))
         %this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1);
   }

(I would have used %this.projectile, but that's already the t2dSceneObject you assign the behavior to. You could give it a better name so that it's less hacky, but this works.)

Hope this helps.