Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9059739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:03:01+00:00 2026-06-16T15:03:01+00:00

I am working on an FPS game. You can see it deployed on Heroku

  • 0

I am working on an FPS game. You can see it deployed on Heroku here (it takes almost ten seconds to load so please wait).

The player can shoot properly but the enemies can’t, even though they’re using the same logic.

Bullets get saturated just after the shooting function is called. I need the enemy to shoot the bullets with some suitable delay, just like happens when the player is shooting.

Here is my code.

   bulletTempEnemy = new J3D.Transform();

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

   bulletHolderEnemy = new J3D.Transform();

engine.scene.add(bulletHolderEnemy);



 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.direction=f;

b.position.fromArray(f);
b.progress = 0;
b.ttl = 50;

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

            if(b.ttl == 0) {
                bulletHolderEnemy.remove(b);
                             }
        }

        bulletHolderEnemy.add(b);
  }

The 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++) {
    bulletHolderEnemy.childAt(i).animate();
 }

I’m using the J3D library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:03:03+00:00Added an answer on June 16, 2026 at 3:03 pm

    For waiting a certain amount of time before calling a function, see https://developer.mozilla.org/en/docs/DOM/window.setTimeout

    To stop the enemy shooting bullets, you should use clearInterval.

    var enemyInterval = null;
    
    ...
    
    if (xdis < 80 && enemyInterval == null) {
        enemyInterval = enemysetInterval(EnemyShooting(), 90000);
    }
    if (xdis >= 80 && enemyInterval != null) {
        clearInterval(enemyInterval);
    }
    

    Note that with your current code, if you’re calling setInterval(EnemyShooting(), 90000); continuously in an update method things will continue to create more “timers” – you may only need one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on designing my first FPS game using JOGL. (Java bindings
I'm working on a game aimed to be deployed on mobiles as native apps,
Good day. I'm working on a fps game, and I have a problem with
I'm working on a game for iOS platform. It's running smooth on 60 FPS
I'm working on a FPS (first person shooter) game at the moment, I want
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working on game where plates will be falling from top to bottom. Some plates
I'm working a game. The game requires entities to analyse an image and head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.