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"

FirstPS Hitscan: Muzzle to Crosshair

alt text

CONTEXT:

I'm building a hitscan rifle using two line traces. The first line trace goes from the first-person camera directly out along its forward vector a scaled length. The second is supposed to go from the muzzle of the gun to the hit location of the first. Basically, the first line trace is for aiming. The second line trace is for the hitscan "projectile's" trajectory.

For the second line trace, I plugged in the hit location of the first (Let's call this the "Target") as the "End" and the muzzle of the gun as the "Start." It worked! Sort of...

About half of the shots weren't registered as hits for the second line trace. I assume the problem was that the length of the second line trace was at the cusp of hitting the target painted by the first. Sometimes the computer's number crunching would round a float up and I'd get a hit, and sometimes it would round down, and I'd get nothing.

MY PROBLEM:

So I'm trying to extend the second line trace's length and my vector math is a bit rusty.

I made a unit vector by subtracting the location of the muzzle from the location of the first hit (The Target) and normalizing it. Multiply the resulting unit vector by a big enough float and I've got my "End" location for my second line trace, right? I set it up in my blueprint and it's not working. Either my math's wrong, my programming's wrong, or my understanding of a line trace is wrong.

Product Version: UE 4.15 Preview
Tags:
capture.jpg (138.7 kB)
more ▼

asked Feb 07 '17 at 04:58 AM in Blueprint Scripting

avatar image

habacabula
38 1 2 6

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

1 answer: sort voted first

Hi,

The vector you are getting then needs to be be added to the "start" vector. Also I don't think you need to substract your muzzle location.

Regards Jan

more ▼

answered Feb 07 '17 at 06:08 AM

avatar image

JanW
136 3 2 9

avatar image habacabula Feb 07 '17 at 02:38 PM

You are absolutely right. Works like a charm now.

Thanks Jan!

(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