Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

WELL first of all I want you to see my game (its deployed on heroku cloud) :

(It takes almost 10 sec to load so please wait for couple of sec)

I have successfully implemented fps shooting .but same logic are not working for enemy to fps shooting ..:(


Bullets gets saturated just after the shooting function is called ..i need enemy to shoot the bullets after some suitable delay just like its happening with fps shooting ...

       bulletTempEnemy = new J3D.Transform();

       bulletTempEnemy.geometry = J3D.Primitive.Sphere(0.5, 4, 4);
       bulletTempEnemy.renderer = J3D.BuiltinShaders.fetch("Normal2Color");

       bulletHolderEnemy = new J3D.Transform();


function EnemyShooting(){

     bulletHolderEnemy.position.x =swat2.position.x;
     bulletHolderEnemy.position.y =swat2.position.y;
     bulletHolderEnemy.position.z =swat2.position.z;

    var b = bulletTempEnemy.clone();

var f =v3.sub(first_person_controller.position,swat2.position).norm();
b.direction = new v3(); 

    b.progress = 0;
    b.ttl = 50;

    b.animate = function() {
    b.position = b.direction.cp().mult(1 + b.progress);
    b.progress += 1;

                if(b.ttl == 0) {



and then code below was called in the game loop function draw()

 var zdis= Math.abs(Math.abs(Math.abs(swat2.position.z) -  Math.abs(first_person_controller.position.z)));
 var xdis= Math.abs(Math.abs(Math.abs(swat2.position.x) - Math.abs(first_person_controller.position.x)));

if(xdis < 80)
setInterval(EnemyShooting(), 90000);


   for(var i = 0; i < bulletHolderEnemy.numChildren; i++) {

library used :J3D (

any help would be appreciated to resolve this saturation probLem of shooting bullets ....:|

share|improve this question

closed as too localized by Byte56, Trevor Powell, Sean Middleditch, Ali.S, Maik Semder Jan 2 '13 at 2:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Generally, if you must include your source code and say "the problem is somewhere in here", the question is too localized. I'm voting to close it as such. Congrats on getting your game as far as you have, but this isn't the place to ask for help debugging your code. See the FAQ about where to ask discussion questions and what kind of questions you should ask here. – Byte56 Dec 30 '12 at 22:36
I dont want u ppl to debug my code ...i just want to know the idea that need to be implemented? – warzone_fz Dec 30 '12 at 22:45
Then rewrite your question without a link to your game or any source code, none of that is needed for conceptual level implementation. Describe in words the way you plan on implementing it and what you've tried already. – Byte56 Dec 30 '12 at 23:18
Also, if you can't take the time to type "you people" instead of "u ppl" then no one will take you seriously. – unixunited Dec 31 '12 at 2:49
The question is really unclear. – Anko Dec 31 '12 at 8:15
up vote 1 down vote accepted

Something that I have used for delays: Have a counter that increments by dt each frame. If it is above the required delay, don't continue to increment it. Then, if it is above the required delay AND the firing condition is true, have it fire the bullet and set the counter back to zero.

Pseudo-code here (in game loop):

if (firingcounter <= firingdelay){
    firingcounter += dt
if (firebulletcondition == true and firingcounter > firingdelay){
    firingcounter = 0
share|improve this answer
thankx alot garan problem is resolved.... – warzone_fz Dec 31 '12 at 14:40

thankx alot garan my problem is resolved :)

var firingdelay=1000;

var dt=50;

if (xdis < 80 && firingcounter > firingdelay){ EnemyShooting(); firingcounter = 0 }

if (firingcounter <= firingdelay){ firingcounter += dt }

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.