Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help with a shooting system, turning numbers into objects

Author
Message
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 6th Sep 2008 23:39
I have been trying to make a good working shooting system for 2 days now. I ended up changing it several times, and here is what i have came up with just now,


the problem i have is turning the "ammo_shot" into physical bullets that will be fired. But I cant come up with how i can do it so the amount of bullets created will correspond with the number of bullets fired.

Help would be appreciated, Thanks

dont hate people who rip you off,cheat and get away with it, learn from them
Terrorist Zero
18
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 7th Sep 2008 00:21 Edited at: 7th Sep 2008 00:50
Note: I'm currently in a state of utter tiredness from work, litterally no sleep last night, and much clubbing so only take this post lightly and vets will probs want to crit my advise too...

How I perceive it is that you want to create a "bullet entity" when you fire? So you'd click the mouse, a "bullet" would be created and shot forward and the world reacts to the effects of the bullet?

First off, creating 1000 bullet objects on screen isn't going to be economical in terms of processing time required and memory needed to store the object data, let alone all the stray polygons on screen that will have to be rendered.

The only way I can figure out a way to do this is to use an array holding data on individual bullets e.g.


If you need up to 1000 bullets and want about 5 parameters (including current bullet position etc) then you'd create the array as


Then for example have the first parameter represent whether the bullet is created (0 for false, 1 for true) then in the same call to increase the ammo_fired variable you'd add in


However, creating an array of that size is not advisable due to the vast amount of memory lost to the creation and storage of the array, so it would be advisable to create a sensible amount of bullets to be calculated at once, for example 5-10, and recycle the array so that when a bullet is no longer needed, the variables used in the array for that particular bullet are freed up for when you reach the final value in the array you can then start from the first value again.

Back when I was developing my FPS game Station 13 (remaking now) I found that it was better to use raycasting to find the theoretical direction of your bullet and then find all the objects colliding with that ray (using sparky's collision dll). Then if the first object hit was an enemy they'd take damage, if it was a wall I'd find out where the collision took place and apply a decal to the wall (by finding the normals, and using a plane and a texture with alpha).

What I'm getting at is that it's far more efficient to calculate what happens when you fire rather than what happens to each individual bullet and rendering the bullet in real time, along with the other 1000 bullets you've fired in the last few minutes (which wouldn't exist if you use the raycasting method). Also considering that when you fire a gun in real life, I doubt you'll be able to see the bullet flying towards your target, so not having a rendered bullet isn't going to make any difference to the aesthetics of the game.


AMD X2 6400+ (3.2GHz) // K9A2 Platinum 790FX Mobo // 2GB Corsair RAM 1066MHz // Powercolor HD4870 512MB OC'ed
HWT
19
Years of Service
User Offline
Joined: 1st Apr 2005
Location: Earth
Posted: 9th Sep 2008 02:47
I'm assuming you're relatively new to DBC programming (hence the many rem statements in the code).

This first one is a simple shooting system:


This second one, builds on the first:


This third builds on the second:


Hello World Tommorrow

Login to post a reply

Server time is: 2024-09-27 20:28:37
Your offset time is: 2024-09-27 20:28:37