Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Please check out my game here: http://still-escarpment-3701.herokuapp.com

The problem is with shooting. The bullets keep on moving with the First person controller instead of moving from the same position and direction from which they were shot.

///////////////////code for shooting from fps///////////////////////////////////
         ///////////////////////////////////////////////////////////////////////////////////
        // the bullet to be thrown and shoot ......

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


        // bullet holder bullets ko apni gun main rakhe ga ....
        bulletHolder = new J3D.Transform();


         engine.scene.add(bulletHolder);
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////

document.onmousemove = onMouseMove;

        document.onmouseup = function(e) {
        var b = bulletTemplate.clone();

            var fz = first_person_controller.forward();
            b.direction = new v3();
            b.direction.fromArray(fz);

            b.position.fromArray(fz).mult(3);
            b.progress = 0;
            b.ttl = 300;

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



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

            bulletHolder.add(b);

        };

The code below is being called in the game loop function's draw().

bulletHolder.position.x =first_person_controller.position.x;
bulletHolder.position.y =first_person_controller.position.y;
bulletHolder.position.z =first_person_controller.position.z;

first_person_controller.rotation.y = mx;

for(var i = 0; i < bulletHolder.numChildren; i++) {
    bulletHolder.childAt(i).animate();
}
share|improve this question
add comment

2 Answers

thankx alot eric for ur response ...

my prob is resolved now ......:)

actually i need to instantiate the bulletholder position inside the click function :)

share|improve this answer
2  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Nick Wiggill Dec 30 '12 at 20:37
add comment

Assuming you are using J3D.js.

Add your bullets to the bulletHolder at the position of the first_person_controller.

// Instead of:
b.position.fromArray(fz).mult(3);
// Do:
b.position.fromArray(first_person_controller.position);
// Or, if you want the bullet to start a few units in front of the player:
b.position = v3.add(first_person_controller.position, fz.mul(3));

And don't move your bulletHolder around in draw(). Remove these lines:

bulletHolder.position.x =first_person_controller.position.x;
bulletHolder.position.y =first_person_controller.position.y;
bulletHolder.position.z =first_person_controller.position.z;

You'll save yourself a lot of time if you keep each scene graph "holder" object like this at the world coordinate system origin.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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