How to make a shotgun spread
Been trying to make a shotgun spread for awhile. Cant seem to get it to work even when I try some of the blueprints i have found they just dont do what i need
It's a twin stick shooter so i wanted it to be more of a fan than a cone. Currently I use a projectile system, the mesh is a pellet with a particle effect that gives a smoke trail
I created a variable "pellets" for how many are in the shell. Fire commands all work fine.
There is a loop. While pellets > 0 There is a variable "spread" which is currently set to -40 I spawn actor pellet . Get all the World transformation and such of a scene component that I added to the weapon mesh "barrel" (has it's x pointed straight in line with barrel, pellets have a velocity of 2000 along X, this works for one pellet fine ) I break the transformation into x,y,z. I then add "spread" to z. And make world transformation Reduce Pellet count by 1 and increase spread by 10 End loop
As the loop exits I have it reset pellet count to 20 and spread to -20 Putting in printstring I know that it does all the pellet counts, I know that it does all the spread changes. And i know that it ends the loop fine.
Just seems there is something weird going on. The pellets only seem to spawn if i am facing certian directions and then only 1-2 along random choices of the spread (So i know that the spread is changing and it's TRYING to spawn them)
Can anyone help?
here is a youtube video of what it does https://youtu.be/oiklm2Zp45o
I will try to get a pic of the blueprint up here later today.
asked Jun 02 '18 at 02:54 PM in Blueprint Scripting
just updating in case anyone comes across this needing help, or about to waste time answering.
I made the projectiles have simple collisions.
The 1x1x1 cube I was using isnt the basic one. It's one in the engine files, it's name includes xyzpiviot or something. When I tried more complex objects without Primatives they would spawn. I GOT COMPLEX too. I was Spawning 40 trees at a time with full materials, lighting and shadows.
playing around I found anything without primatives would spawn just fine, while it seemed that anything i tried (think they were all imported from blender) what had convex primatives would only spawn up to 4.
I copied the little cube that had almost nothing to it and moved it into a different file, renamed it. At the top i choose collisions and "simple box". figured it would be the easiest to calculate.
Works great. Generates hit events, bounces (I might attempt to use sphere as the bounces are admittedly very strange in behavior at this time)
My theory on this is: Using such things as a quadproccesor there can be data being added/calculated etc in the different cores.
Attempting to calculate a primative for a really small UV Sphere with all that it entails might just take a fraction of a fraction of a second, but if one of the other cores has now processed the loop iterations.....the actor spawns in the wrong place. Then when it checks the loop again it's already completed.
if anyone knows anything about this i would love more detail. And if there is a way to solve it as it was, such as setting a processing order
answered Jun 06 '18 at 07:39 AM
It sounds to me like you're problem is that you're spread calculation is incorrect.
What you should look at doing is getting the 'forward' direction of the gun barrel (it may not actually be the forward depending on how you're setup, so substitute with whatever works - may be camera direction). You should also know the point at which all the pellets fire from (possibly a socket at the end of the barrel).
For a normal, single shot that fires straight you'd just fire from the end of the barrel in the forward direction. The forward vector should be normalised so it describes only the direction out of gun barrel.
For a spread shot you'd want to modify that forward vector (again, making sure it's normalised) by rotating it through some degrees in whatever axis you are interested in.
You might find this easier to achieve by using the VRandCone method:
I assume there is a blueprint node for this too, maybe earch for Random Cone and see what appears (sorry, never done this in blueprints)
To actually see what's going wrong I strongly recommend taking advantage of the DrawDebugLine ( Blueprints: https://api.unrealengine.com/INT/BlueprintAPI/Rendering/Debug/DrawDebugLine/index.html or CPP: http://api.unrealengine.com/INT/API/Runtime/Engine/DrawDebugLine/index.html ). You can actually draw a line from the the end of the gun barrel in the expected direction of the pellets so you can visually see if any of your maths is wrong
answered Jun 02 '18 at 09:12 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here