Creating bullet bodies

Zurzaza
Posts: 11
Joined: Tue Aug 24, 2010 9:34 pm

Creating bullet bodies

Post by Zurzaza »

Hi everyone.
I'm currently developing a game, that uses irrlicht for graphics and bullet for physics.
At the moment, i have been programming the weapon system, and (for balistic feedback) i need to create the bullet bodies each time the mouse is pressed (a new bullet body is created).
The trick can work for weapons like pistols, or slow guns, but for machine gun (that shots a lot of bullet per seconds), the method doesn't work well (the game starts dropping FPS). That just because the physics engine needs to alloc a lot of body in a little time.

My idea was to allocate a bunch of bullet bodies before loading the level, than use that when shooting and "reset" their status after a collision, but i don't think is a great idea.
Anyone has other methods?
Thank you very much ;)
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Creating bullet bodies

Post by lulzfish »

For guns you can usually get away with raycasting unless you're trying to simulate a sniper rifle with realistic delay over a huge range.

You should look for btDiscreteDynamicsWorld's raycast functions.

If you want some bullet delay or drop, you can do multiple raycasts spread over several frames, but in edge cases that can allow a fast-moving object to skip in between the raycasts, so you might also consider overlapping them slightly.

Usually you don't want an actual physics body unless you're simulating something rather large that moves slowly and needs to bounce around realistically, like a grenade. For small objects like bullets, most games just pretend they are a ray, and it saves some processing power.