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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How can i get the angle of the cube's face i'm looking at?

Hello, i have a cube and i would like to know the angle between my forward vector and the cube's face forward vector that i'm currently looking at. I have the following working logic:

 FVector Normal = Cube->GetTransform().InverseTransformVectorNoScale(HitResult.Normal);
 
 FVector Vector;
 FString Side;
 
 if (Normal.Equals(FVector(1.0f, 0.0f, 0.0f)))
 {
     Side = "Front";
     Vector = Cube->GetActorForwardVector();
 }
 else if (Normal.Equals(FVector(0.0f, 1.0f, 0.0f)))
 {
     Side = "Right";
     Vector = Cube->GetActorRightVector();
 }                
 else if (Normal.Equals(FVector(-1.0f, 0.0f, 0.0f)))
 {
     Side = "Back";
     Vector = -Cube->GetActorForwardVector();
 }                
 else if (Normal.Equals(FVector(0.0f, -1.0f, 0.0f)))
 {
     Side = "Left";
     Vector = -Cube->GetActorRightVector();
 }                
 
 FVector Value = GetTransform().InverseTransformVectorNoScale(Vector);
 
 float Angle = FMath::RadiansToDegrees(FMath::Atan2(Value.X, Value.Y));

This gives-me -90º when i'm looking directly to the face and it works, but i'm sure there has to be a better way to do this ! Thank you.

Product Version: Not Selected
Tags:
more ▼

asked Oct 17 '14 at 01:17 AM in C++ Programming

avatar image

xlar8or
6k 161 129 304

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

2 answers: sort voted first

I really overcomplicated this, after spending some time i ended up with:

 FVector Normal = GetTransform().InverseTransformVectorNoScale(HitResult.Normal);
 
 float Angle = FMath::RadiansToDegrees(FMath::Atan2(Normal.X, Normal.Y));

The first step wasn't necessary at all :P

more ▼

answered Oct 17 '14 at 03:18 PM

avatar image

xlar8or
6k 161 129 304

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

A trace will return the normal angle, but I am not sure what context you are needing this info in so I don't know how useful that will. be.

more ▼

answered Oct 17 '14 at 01:36 AM

avatar image

Hyperloop
1.2k 57 67 99

avatar image xlar8or Oct 17 '14 at 11:15 AM

I am already using a trace to get the normal:

 FVector Normal = Cube->GetTransform().InverseTransformVectorNoScale(HitResult.Normal);

Notice the HitResult.Normal. I'm using this to know when i'm looking directly into a cube's face so i know i can play a vault over / wall climb animation, otherwise he would play the animation in the wrong direction.

(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