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"

Establishing direction vector between two actors

I'm trying to check if actors within my TArray are standing within an imaginary cone in front of the player. It seems like the fastest way to do this would be to take the dot product of the player's forward facing, and the vector from the player to the target. The former is easily done with FVector:DotProduct, but I can't find a method for the latter- is one built in? I tried the following (as subtracting two locations should yield direction). but it gave me an angle of -1.#IND00, which doesn't seem right:

 float dProductAngle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(myActor->GetActorForwardVector(), (targetList[i]->GetActorLocation() - myActor->GetActorLocation()))));
Product Version: UE 4.8
more ▼

asked Jun 23 '15 at 07:51 AM in C++ Programming

avatar image

266 97 67 83

avatar image Pierdek Jun 23 '15 at 08:24 AM

This should be normalized:

 (targetList[i]->GetActorLocation() - myActor->GetActorLocation())

 Maybe (targetList[i]->GetActorLocation() - myActor->GetActorLocation()) returns 0,0,0 ? Their in the same position?

Beside use FMath::Acos instead of acosf.

avatar image HInoue Jun 23 '15 at 08:30 AM

Hmm, I normalized the subtraction and switched to Fmath::Acos, but it gives the result result. I get -1.#ND00 from every position I test it in, so I'm pretty sure it isn't returning 0,0,0...

Current version:

 float dProductAngle = FMath::RadiansToDegrees(acos(FVector::DotProduct(myActor->GetActorForwardVector(), (targetList[i]->GetActorLocation() - myActor->GetActorLocation().Normalize()))));
avatar image HInoue Jun 23 '15 at 08:35 AM

That's my syntax problem, you're right about the method... after fixing it, this works perfectly; thank you!

 FVector normDirection = (targetList[i]->GetActorLocation() - myActor->GetActorLocation());
         float dProductAngle = FMath::RadiansToDegrees(acos(FVector::DotProduct(myActor->GetActorForwardVector(), normDirection)));
avatar image Pierdek Jun 23 '15 at 08:41 AM

Beside use FMath::Acos instead of acos ;)

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

0 answers: sort voted first
Be the first one to answer this question
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