[Resource | Code] Conical bullet spread! *UPDATED*

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Post Reply
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

[Resource | Code] Conical bullet spread! *UPDATED*

Post by Snarboo »

Here's a quick and dirty conical bullet spread example! Now it's been updated to correct the fixed point issue, so bullet patterns should no longer form bullseye patterns. Be sure to redownload the file!

Code: Select all

/* 
** Conical Bullet Spread Example
** Formula works like this: 
**		X = (Radius * Cos(Angle)) + Offset
**		Y = (Radius * Sin(Angle)) + Offset
**
**		Where Radius is the size of the circle you want to draw (can be 
**		randomized), Angle is an angle between 0 and 360 (can be fixed or 
**		random), and Offset is how offset the circle is from your crosshair.
**
**	NOTE: Two of these values must be identical between X and Y! Radius must be 
**		  the same and angle must be the same! However, if you want elliptical
**		  bullet patterns, simply change the X or Y value to be larger or
**		  or smaller than the other.
**
**		  Weapons that make use of this MUST use the EXPLICITANGLE flag! Same 
**		  goes for the equivalent monster function A_CustomBulletAttack.
**
**		  Conical spreads are a bit limited with weapons, since weapons do not 
**		  have acces to user variables, but they do have access to arguments. 
**		  There are problems relating to fixed point numbers and arguments, but
**		  a workaround exists by using the following formula:
**		  X = (((Radius * 10) * Cos(Angle)) * 0.1) + Offset 
**		  Y = (((Radius * 10) * Sin(Angle)) * 0.1) + Offset
**
*/
Spoiler: Q&A
Spoiler: Known Issues
Attachments
conicalspread.pk3
Pickup a chaingun, or type "give conicalchaingun" in the console.
(1.1 KiB) Downloaded 217 times
Last edited by Snarboo on Thu Jan 01, 2015 11:52 am, edited 4 times in total.
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [Resource | Code] Conical bullet spread!

Post by Nash »

Image

Looks like one of those mysterious alien pattern thingies you find in obscure places... =D
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

Re: [Resource | Code] Conical bullet spread!

Post by Snarboo »

I MAY have done the math slightly wrong! :p But yeah, I recommend using floats for this so that doesn't happen.

Edit:
Actually wait, can arguments store floats?!
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [Resource | Code] Conical bullet spread!

Post by Nash »

Also, and you may already know this but, this doesn't seem to respect player pitch... in OpenGL with an extreme view pitch, the cone doesn't work...
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

Re: [Resource | Code] Conical bullet spread!

Post by Snarboo »

Yeah I've definitely screwed up the math somewhere! I'll look into it.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: [Resource | Code] Conical bullet spread!

Post by Enjay »

Nash wrote:Also, and you may already know this but, this doesn't seem to respect player pitch... in OpenGL with an extreme view pitch, the cone doesn't work...
You're not running a build with this bug are you?

http://forum.drdteam.org/viewtopic.php?f=25&t=6492

That has now been fixed if you are.
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [Resource | Code] Conical bullet spread!

Post by Nash »

Enjay: no, my screenshot is ZDoom and the software renderer. :D And the behaviour of this conical spread not working correctly with extreme view pitch is also on an old GZDoom build without pixelratio.

(I haven't updated to any of the new pixelratio builds yet)
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

Re: [Resource | Code] Conical bullet spread!

Post by Snarboo »

The cone does get very skewed at greater pitches, but I'm not sure how to fix that if it can be fixed.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: [Resource | Code] Conical bullet spread!

Post by Enjay »

Nash wrote:Enjay: no, my screenshot is ZDoom and the software renderer.
...but I was responding to
Nash wrote:in OpenGL with an extreme view pitch, the cone doesn't work...
;)
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

Re: [Resource | Code] Conical bullet spread!

Post by Snarboo »

I just tried this with a fixed square spread, and the same thing happens: It gets very skewed as you look up and down. Wonder if this is a limitation of the hitscan code, or a limitation of FBF_EXPLICITANGLE?

Edit: Offset doesn't have to be the same with both values, so I updated the first post! I'm also looking into some way of correcting the cone at extreme pitches.

Edit 2:
I did some simple tests in other ZDoom games with different weapons, and it seems that at extreme angles, there is no horizontal spread at all! I'm not sure I can fix this issue, but given other weapons behave the same way, I guess I don't need to.
User avatar
Snarboo
Posts: 2599
Joined: Tue Nov 29, 2005 4:37 am

Re: [Resource | Code] Conical bullet spread! *UPDATED*

Post by Snarboo »

I've fixed the "bullseye" issue, so be sure to redownload the example file!

Edit:
Fixed a math related error.
User avatar
TiberiumSoul
Posts: 1065
Joined: Fri Jan 20, 2012 11:29 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: My Computer...

Re: [Resource | Code] Conical bullet spread! *UPDATED*

Post by TiberiumSoul »

sorry for bumping this but... did anyone ever figure out how to get missiles to work with this?
Post Reply

Return to “Script Library”