Moving Bullets

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
isiahil

Moving Bullets

Post by isiahil »

I am a newbie and doing a FPS and i want to know how should i do the bullets? How do i move make it so that if they hit the computer, they take off damage? or if they hit the wall to splat? How do i do collision detection on them?

1 more question, How do i move the bullets from the gun into a straight line. Its a paintball FPS.
Rat
Posts: 51
Joined: Wed Mar 10, 2004 7:05 am

Post by Rat »

I was having lots of trouble setting up more than one collison node that you can detect and spawn items until this tutorial came out here:
http://www.mercior.com/tut-newton.shtml

There was one compiling problem I encountered and got cleared up that I will share with you. It will probably give you an error when you try to compile it unless you physically add the folders to where you have extracted the newton SDK to for header files and library files. (Of course you also need to dump the Newton.dll in the folder where you will be running your executable from once you get it compiled as well, but the downloads for this example has an already built Newton.dll).

The main error that came up that I had a problem with was that I needed to turn off precompiled headers in the project settings.

If you study the example and start playing with it, you should be able to figure out how to turn the Crates into Bullets.

HTH
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

(Assuming you know how to use OOP and create multiple bullets in an array)

If you open the TechDemo project (in the examples folder), specifically the CDemo.cpp file, you'll see how bullets are done.

They are animated by testing a line collision between the camera and the nearest part of the level, and then animated between those two points. When the time is up (it's reached the wall) the bullet explodes. Causing the effect of a solid wall.

Collision detection for dynamic objects isn't shown in the tech demo.

To do this, you need to iterate through your array of all your currently moving bullets, and compare its position with every dynamic object it is supposed to hit by iterating through the 'enemy' array once for every item in the bullet array, and checking if the current 'enemy' and 'bullet' are overlapping.

If a bullet is overlapping (colliding with the bounding box of) a dynamic object, then they have been hit by a bullet, and you should make that bullet explode, and that enemy loose life.

Of course, you should optimise this by only checking bullets against objects that they should hit, and possibly making you own method of only checking against the objects that are close by (saving you checking against every object in the level)
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Rat wrote:
If you study the example and start playing with it, you should be able to figure out how to turn the Crates into Bullets.
The only problem I can see with that is that as I introduced a number of crates into the world (>200), the physics calculations seemed to start taking an insanely long time, bringing my FPS well below 30. It seems that many bullets would cause this problem as well, though perhaps more optimising can be done, since it seemed that the calculation time was increasing disproportianately fast as I added more crates. I'm not really familiar with the Newton engine yet, so there is probably a way to speed things up.
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

One thing though, is that bullets get destroyed, the crates do not. One thing i've seen (i think it was here), was creating a ray, and setting it as a physics object, but i don't know if that'll work
The Robomaniac
Project Head / Lead Programmer
Centaur Force
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

true, unless you have some sort of very fast repeater >50 or so bulets aren't all that likely
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

Theres 2 approaches to bullets in a FPS game - projectile based and hitscan based.

Hitscan weapons simply cast a ray when the player shoots and see if the ray collides with anything, it means your gun instantly damages whatever its pointing at, and its a good technique to use for pistols, machine guns, etc. You should use the irrlicht raycasting functions for this.

The other approach is projectile based - where you create some sort of moving object that damages objects when it collides with them. This effect is handly for guns such as rocket launchers / grenade launchers. For this you could use either newton or irrlicht, but I would think that using just irrlicht would be easier for a beginner.
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Mercior, for Projectile bullets, would you use a built in collision feature of Irrlicht (and if so, what is it), or would you keep an array of all the active bullets and test to see if any of them overlap with something that can be hit?

If the latter, would you test the x,y,z position for an overlap with the bounding box of an object (that Irrlicht provides), or compare their distances with an equasion (sperical collision)?
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

I think it would probably be easier to use Newton with projectiles, because one can set a callback for when the bullets collide, rather than having to constantly test them yourself
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Awesome, thanks Electron. Judging from the Newton tech demos, I bet Newton would be really smart about which ones to check for collision too, rather than using brute force and testing all of them. When I was throwing heaps of bouncy balls at that stone tower, it was slowing a bit, but when they all stopped bouncing around so much and were rolling about on the ground slowly, the frame rate was silky smooth, even though there were 100's of bouncy balls on the ground now.
Post Reply