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"

Best way to setup tracing for hitscan weapons


I'm currently working on a multiplayer shooter and need help with line-tracing for my hitscan weapons. My current approach to doing the tracing is to:

  • First trace from my eye-location to 10 000 units in front of my eye-location. This gives me wherever the crosshair is pointing at.

  • Then trace from the weapon's muzzle to wherever the crosshair is pointing at.

The problem is that, this is a third person shooter, and by tracing from the camera's location, it would hit objects that are not only in front of the weapon, but also behind the player. Please see the included picture.

So my question was if this really is the best way to trace for hitscan weapons, or if there maybe is another, better way? If there is no better way, then how could I improve what I already have? (Possibly tracing from like 500 units to 10 000 units? Instead of 0-10000 units which is what I have now?

Thanks in advance :)

~ Stefan

alt text

Product Version: UE 4.19
more ▼

asked Jun 12 '18 at 08:26 PM in C++ Programming

avatar image

116 4 7 14

avatar image HarryHighDef Jun 13 '18 at 02:14 PM

Why not start your trace at a plane where the character is. You can use the Project point onto plane function. Set the plane base to be your character location and the plane normal to be your camera forward vector. That way your trace will start beside the character and should only be able to hit things in front of them.

avatar image Steferich Jun 13 '18 at 05:19 PM

I'm not sure if I understand.. and what does the "project point onto plane"-function do? Also, if I'm tracing from my character location in the direction of my camera, wouldn't it be offset in relashion to the crosshair, in which the crosshair wouldn't be completely accurate?

avatar image ZeroParadigm Jun 13 '18 at 11:08 PM

I think what he is saying is to create a plane in space at the location of your character. Imagine that this plane is always perpendicular to the forward direction of your camera, but it's local origin is the origin of the character (maybe even muzzle location of the weapon). When you rotate the camera, the plane rotates also. So when you project the forward vector of the camera onto the plane, you have a reference point which ignores the distance from the camera to anything orthogonal to the character. Use that as your starting point, then trace forward to find a hitresult.

A plane consists of two values, an origin (vector) and a surface normal (normalized vector). So the idea is to cut out all of the geo between the camera and the backspace of the character.

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

1 answer: sort voted first

I've just seen a youtube video about this and this is absolutely what I'm looking for. So as I understand it, basically what a projection of a point onto a plane does is moving the point forwards and blocking out the space behind the player? Thanks alot to HarryHighDef and ZeroParadigm! :)


more ▼

answered Jun 14 '18 at 05:30 AM

avatar image

116 4 7 14

(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