x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: UE 4.18
Tags:
more ▼

asked Jun 02 '18 at 02:54 PM in Blueprint Scripting

avatar image

Cultusfit
43 4 4 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

PROBLEM SOLVED:

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

more ▼

answered Jun 06 '18 at 07:39 AM

avatar image

Cultusfit
43 4 4 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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:

 /** 
  * This is a version of VRandCone that handles "squished" cones, i.e. with different angle limits in the Y and Z axes.
  * Assumes world Y and Z, although this could be extended to handle arbitrary rotations.
  */
 static CORE_API FVector VRandCone(FVector const& Dir, float HorizontalConeHalfAngleRad, float VerticalConeHalfAngleRad);

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

more ▼

answered Jun 02 '18 at 09:12 PM

avatar image

phil_me_up
1.5k 6 6 12

avatar image Cultusfit Jun 02 '18 at 10:43 PM

alt text

Wow...I didnt even realize how messy I had gotten here just trying so hard to get it to work with changes/moves.

Trying your debug command. As it turns out i have to change y rather than z. I now have a nice fan of purple lines fireing from the shot gun. I had presumed as it was using the barrel scene component that I would just get it's world location/transformation and alter it the same way I would in the viewport for the mesh to change the direction (that's even how I chose my numbers by changing the z value of the scene component until it was at the angle i desired.

alt text

Problem I'm having now its it always fires "down". That is at least a bit more manageable. Although I dont really understand why getting the world location/transformation/rotation of a component doesnt get it's rotation....

If you happen to be able to explain to me why i change y instead of z I would appreciate it. Not understanding WHY i will probably make similar mistakes all along the way. And if you have any idea how to make it point in the direction of the object who's rotation it is getting....

Okay....doing the same thing with the pellets...it instead actually fires all of them in the appropriate direction but they fire from points to left and right of the pawn...basically a WALL of bullets rather than a cone. Changing Z they fire from the barrel and a column above it. So neither of those work to to set the rotation....but it has a transformation input rather than a vector input. I figure trying to break it into a vector and change it then put back in is causing the problemsalt text

9ysrhpg.jpg (229.8 kB)
9ysrhpg.jpg (200.3 kB)
9ysrhpg.jpg (488.2 kB)
avatar image Cultusfit Jun 03 '18 at 09:06 AM

Alright. Got around to moving the shotgun into a macro. Did a lot of testing. I put a cone in and made sure the object I was using DID rotate after each iteration of the code then, reset to the start position. Did several debug lines

Then i made it only move ONE iteration and fire ONE pellet, going through the whole set in 20 shots rather than a single 20 pellet shot.

As everything worked out I put a delay in the sequence so that it would wait 0.2 seconds before checking the branch statement again (as seen in the photo). This resulted in every spawn working across every iteration of the "spread" as desired except for the low speed.

video here: https://youtu.be/NfTiQLMXD8Y

alt text

if anyone knows how to make it run at full speed while still spawning every instance I would appreciate it.

untitled.jpg (185.6 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question