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.

DarkBASIC Discussion / How do i get better bullet collision?

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 17th Nov 2008 03:39
I have a FPS game with 2 weapons and 10 spheres that will come at you and attack and its supposed to destroy the "enemy" in 2 hits with the machine gun and 4 with the pistol but its not detecting collision very well so it takes like 10 hits for the pistol and like 5 give or take to kill with the machine gun

Im using regular dbc collision. i have attached the game and the media.

there might be a few things like after it prints points it prints the variable dst i was working on making the pistol shooting and sound line up and i forgot to take it off there could b sum other odd random stuff but ignore it haha. oh and i couldn't get wall collision to work so ignore the walls haha

Attachments

Login to view attachments
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 17th Nov 2008 14:51 Edited at: 19th Nov 2008 16:49
to anyone who was gunna help sorry i already figured it out

it sounded like a long way around but it tripled my fps for sum reason

i used a function



where pistol is witch gun im using(Pistol=1 or 0) and then the call for this is in a for next loop thing so enemy checks the enemy object each time the for next loop goes through and it works quite well i might add
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Nov 2008 19:35
Nice, iwas just about to say use a distance function.

now i gotta say use a code button.........

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Nov 2008 20:17 Edited at: 17th Nov 2008 20:21
@Caleb1994
The distance formula has come up on these forums 1000's of times and it is very useful but it is also very slow because of SQRT and ^2. And, if you do not need the exact distance between 2 points (or objects), that is, you only need to test true or false if something is within a specified distance (like 150 in your function above) you can speed up the check significantly.

The general concensus on the forums is to eliminate the SQRT and multiply the differences directly instead of using ^2. You then compare the result to the squared value of the distance to check.

The formula looks like


So to speed up your function, it could look like:



Enjoy your day.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Nov 2008 23:34 Edited at: 17th Nov 2008 23:35
whoa,latch............never thought of it like that...thanks. the sqrt and ^2 are how important of a slow? enough to take maybe....2-5 frames a second away?....

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Nov 2008 02:49 Edited at: 18th Nov 2008 02:50
Well, over time it adds up in milliseconds(ms) . The following test runs the distance formula and the formula without SQRT. What's weird is it seems functions return floats faster that integers. I set up the distance formula to return both a flaot and an integer and in all cases the float result was faster... Anyway, both functions are run over 1,000,000 iterations and the results displayed in ms. The distance within on my machine runs about 20 ms faster. Not much, but checking multiple objects per loop over the life of a game adds up...



Enjoy your day.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 18th Nov 2008 03:30
Latch, I ran it, and I got a 82 ms diff. Enough to make a long term difference...

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Nov 2008 04:17
Thanks for testing it out!

If you guys really want to see a lag, I had already optimized the distance formula a bit so try replacing
dist#=sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
with
dist#=sqrt(((x2#-x1#)^2)+((y2#-y1#)^2)+((z2#-z1#)^2))
in the original distance formula function. You can see just how much ^2 also slows things down. I get a difference of almost 400 ms.

Speaking of optimizing, I decided to optimize both versions of the functions. By eliminating the dx# dy# and dz# assignments and getting rid of maxdist#*maxdist# inside the within_dist function, things really speed up. I get a difference of about 150 ms with these changes:



Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Nov 2008 01:15
ok thanks for all that latch

but this is gunna sound dum but how do you use the code button i pushed it that time and i put my code after it and it didnt work as you see and iv tried putting the code in the brackets and it didnt work im confused :/
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 19th Nov 2008 03:48 Edited at: 19th Nov 2008 03:49
(code)code here (/code)
With the ( and ) being [ and ]


I download memory.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Nov 2008 16:47
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Nov 2008 17:01
one more question what is a good frames per second cuz write now im getting 99 just wondering

i was getting 37 give or take but that function like i sed sped it up abunch haha
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 19th Nov 2008 17:22 Edited at: 19th Nov 2008 17:22
The FPS depends on how much you are running. 99 is okay. 37 is bad.
Personally, 150+ is good.

But then again, the commercial quality Sims 2 ran at 21 FPS on one of the best computers possible for it.

So there you have it.

Please edit your posts instead of double posting. It's just the rules.


I download memory.
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th Nov 2008 17:42 Edited at: 19th Nov 2008 17:45


Some questions and thoughts (I can't check any of these out from my location)

1. Shouldn't collide=((dx#*dx#)+(dy#*dy#)+(dz#+dz#)) be +(dz#*dz#)
2. Shouldn't enemylife, be enemylife# if you are subtracting 0.5?
3. Is there any performance gain if data remains of the same type. for example having collide be collide# and maxdist maxdist#?
4. What about making the maxdist a constant or just taking out the multiplication operation (how much performance gain), or just making it maxdist#= 22500.0
5. Is there any gain from checking against 0 first, are the only choices values for pistol 1 and 0?, eliminating the if after the else, and/or replacing if collide<maxdist with with if collide-maxdist>0. I'm not thinking to sharply right now, but I'm sure there is still a better way to code that if, and it should be unecessary to check the value of collide-maxdist twice.

6. What's faster in DBC?
enemylife#=enemylife#-.25
decrementing enemy life by .25 (dec enemylife# .25)
or is there a enemylife# -=.25

I'll have to try these when I get home

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Nov 2008 22:58 Edited at: 19th Nov 2008 23:02
1. im geussing a typo
2. does the # make a difference???? and know that $ is string and # is numbers but i'v seen alot of people using the variables without it so i didn't think it mattered
3.idk
4.idk
5. as i said in the first post yes 1 and 0 are the only values for pistol as i only have a pistol and a machine gun. so if pistol=0 then you have the machine gun. and if i remove the if after the else that wouldn't work would it???? as for the maxdist twice thing i see what u meen it would make for sense to do it like this




thats all the awnsers i have.

Thanks for the info bout FPS irojo! ya i know 37 is way bad

do you think i should try and get the fps up higher then 99 cuz i put in a few if then things playing around with sumthing and i put no more then 3 of em in and it dropped the fps to 37 again
i took em out and it jumped up to 99 or 100 again grrrrr any suggestions???

sorry bout the double post. i forget about editing and i didn't know it was a actual rule all i knew was people didn't like it
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Nov 2008 23:46
Quote: "3. Is there any performance gain if data remains of the same type. for example having collide be collide# and maxdist maxdist#?"


@Caleb
# means the value has a decimal point. It is a floating point value or a real number. So there is a difference. Use # when you want a decimal point. Outside of DBC functions, integers are supposedly much faster than floats.

As to 3. , I've been running tests with functions specifically using floats versus integers. Floats seem to be faster in DBC functions. It should be the other way around, but floats seem faster in functions.

Quote: "4. What about making the maxdist a constant or just taking out the multiplication operation (how much performance gain), or just making it maxdist#= 22500.0"

Yes. I suggest that later in the post.


Quote: "6. What's faster in DBC?
enemylife#=enemylife#-.25
decrementing enemy life by .25 (dec enemylife# .25)
or is there a enemylife# -=.25"


Don't know. I thought dec or inc would be slower because it's another function call that has to be interpretted, but I've discovered the assigned operator (=) is super slow probably because DBC has to determine if it's a comparison or an assignment. Yeah, run some test. I'd be curious to know.

There is no -= .

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Nov 2008 03:14
oh ok thanx i didn't know that

Login to post a reply

Server time is: 2025-06-07 20:28:35
Your offset time is: 2025-06-07 20:28:35