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"

Feed LineTrace random spread into SpawnActor spawn transform?

I have a blueprint with firing logic, where I'm using both a LineTraceByChannel node for hit detection and a SpawnActor node for bullet trail visuals.

I've managed to get the LineTraceByChannel to have a random spread.

alt text

How do I use the same LineTrace random spread to influence the SpawnActor Spawn Transform? How can I get their paths to line up?

alt text

Product Version: UE 4.19
Tags:
more ▼

asked Jul 13 '18 at 01:48 AM in Blueprint Scripting

avatar image

brokenstyli
18 2 5

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

1 answer: sort voted first

You want to know the location of where the trail will start from and end at (I'm assuming this is a gun since we are talking about bullet trails), that would be the location where your trail starts and spawns. So for the location of the transform you either keep it the same if it's the correct start location or you put your gun muzzle as a location (if you don't have a way of getting the gun muzzle location you can just attach a socket or if it's not a skeletal mesh some invisible object).

For the rotation you want to calculate the direction, there's already a node that does that for you called "Find look at rotation", for the start you use the same location that you plugged into the transform and for the target you use the trace hit/end location (you could either set the random spread to a vector variable before spawning the trail and use that variable for both the transform of the trail and the trace end location or move the trail after the trace and get the exact hit or end location by breaking the Out Hit of the trace). If your trail is done properly that should rotate it to the correct direction.

more ▼

answered Jul 13 '18 at 02:37 AM

avatar image

Enjobg
121 1 3 5

avatar image brokenstyli Jul 13 '18 at 08:14 AM

Cheers, that worked great!

For anyone looking into this in the future, here's the blueprint;

alt text alt text

("find look at rotation" is the same node in both screenshots)

Make sure the linetrace happens before the spawnactor.

solution1.png (88.1 kB)
solution2.png (60.9 kB)
avatar image brokenstyli Jul 13 '18 at 08:44 AM

Discovered a minor issue with this solution. If there's no static mesh for the LineTrace to hit, or if the LineTrace length is too short that it doesn't touch anything then the bullet trail will target the world origin as the target end location.

Solution to this is to create a skybox out of 6 cubes with a transparent material. And then make sure that the Line Trace By Channel's length is utterly massive that it always collides with the outer skybox.

avatar image Enjobg Jul 13 '18 at 09:08 AM

Yep, you could use the trace end vector instead (from the bottom of the hit result), you'll also want to move that SpawnActor node to be called after the line trace instead of before (just in case it screws something up because of order of execution). Have a branch between the line trace and spawn actor with blocking hit as the bool, on true spawn the trail using rotation from the hit location, on false use the trail end instead.

(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