How do you give projectiles inaccuracy?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
- Lt.blam
- Posts: 87
- Joined: Thu Jun 16, 2016 9:01 pm
- Location: https://www.youtube.com/watch?v=fq3abPnEEGE
How do you give projectiles inaccuracy?
As the title reads. Is there a way to add projectile inaccuracy?
Re: How do you give projectiles inaccuracy?
In A_FireCustomMissile add random(-x, y) for both angle and pitch where -x and y can be the same numbers, which is usually used most. The negative number ensures the projectile doesn't just fly in one single direction everytime, say, all projectiles go above the crosshair, for example.
Example:
You can also use frandom(-25.0, 25.0), though I don't know if there is much of a difference. Do take note that the area the projectiles will hit is a square. Using frandom may make the square less perfect, though that's just an observation of mine and could be just an illusion.
Example:
Code: Select all
A_FireCustomMissile("TestMissile", random(-25, 25), 1, 0, 0, 0, 0, random(-25, 25))
Last edited by Accensus on Fri Aug 26, 2016 1:59 pm, edited 1 time in total.
- Lt.blam
- Posts: 87
- Joined: Thu Jun 16, 2016 9:01 pm
- Location: https://www.youtube.com/watch?v=fq3abPnEEGE
Re: How do you give projectiles inaccuracy?
No problemo, pal.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
Re: How do you give projectiles inaccuracy?
There is a way to "math out" the spread so that it's circular, but is a bit of a pain. Where frandom is useful, though, is to enhance the precision of randomness, since it does not need to be in whole numbers. This means that, for example, shotguns that fire a lot of pellets will not appear to be firing on a grid.Lud wrote:You can also use frandom(-25.0, 25.0), though I don't know if there is much of a difference. Do take note that the area the projectiles will hit is a square. Using frandom may make the square less perfect, though that's just an observation of mine and could be just an illusion.
Re: How do you give projectiles inaccuracy?
That explains a whole lot. Thanks, ww!
Re: How do you give projectiles inaccuracy?
If you want the projectile inaccuracy to appear less square, you can multiply 2 random results. Example:
You will have to adjust the math a bit since now the possible outcome can be much bigger, but at the same time what it will do is make it appear much more likely that the result appears closer to the crosshair. Because of this, and because of two checks (2 axes) it is far more likely that the result will appear on a line rather than a corner, or somewhere near the center.
Corner shots will still happen, but their incidence will be less often. You probably won't even notice it unless you enable decals and stare at the patterns on the wall.
Code: Select all
A_FireCustomMissile("TestMissile", random(-25, 25)*random(-25, 25)/25, 1, 0, 0, 0, 0, random(-25, 25)*random(-25, 25)/25)
Corner shots will still happen, but their incidence will be less often. You probably won't even notice it unless you enable decals and stare at the patterns on the wall.
- NeuralStunner
-
- Posts: 12326
- Joined: Tue Jul 21, 2009 12:04 pm
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia with Vulkan support
- Location: capital N, capital S, no space
- Contact:
Re: How do you give projectiles inaccuracy?
You could simplify that by quite a bit, having the desired angle spread in the first frandom() and (-1,1) in the second:
Though I've gotten good enough results from adding two frandom()s at half the desired angle apiece. On the surface you wouldn't expect it to make any difference, but the outcome tends to look less square to me. (Statistically, adding two random numbers skews the results toward the average.)
Code: Select all
FRandom(-5,5)*FRandom (-1,1)
Re: How do you give projectiles inaccuracy?
I never knew about adding randoms together, so that's a good idea, too.