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"

How do I find the distance to a target along the players aim, if the player is not looking directly at the target?

How do I find the distance to a target along the players aim, if the player is not looking directly at the target?

Ive set up a targeting function that currently gets the closest target within an FOverlapResult. I need the target closest to the players aim, not the player themselves.

I think(mathematically) this is a matter of finding the longer cathetus of a right angle, where the hypotenuse is the actual distance to the target.

Im not familiar with what functions, if they exist, would do this.

Product Version: Not Selected
Tags:
more ▼

asked Mar 26 '15 at 12:12 AM in C++ Programming

avatar image

Erdrik
423 47 52 76

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

1 answer: sort voted first

Hi,

There is a function is UE that calculate the shortest distance between a point and a line.

Use it between your target position and your aim vector. be aware that the line will be considered as infinite it s not a segment.

If I remember properly it s in the Math part. I m not at home so I can t give you the name but use the search and I bet you will find it...

more ▼

answered Mar 26 '15 at 07:50 AM

avatar image

Elvince
494 43 70 157

avatar image Elvince Mar 26 '15 at 08:43 AM

it's FMath::PointDistToLine

avatar image Erdrik Mar 26 '15 at 01:50 PM

Thank you! That works nicely.

avatar image Erdrik Apr 04 '15 at 08:41 PM

Bit of an update: I don't know if its intended, but FMath::PointDistToLine does not actually get a point along the line. It seems to get a point on the opposite side of the targetpoint from the line.

Fortunately, I was still able to make some custom code based off this to meet my needs.

(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