Ivan3z
(Ivan3z)
December 27, 2024, 9:27am
1
I expected these two vectors to be perpendicular to each other.
However, they point in the same direction.
Also when the pawn turns the vectors does not move.
this is the code:
DrawDebugLine(GetWorld(), NPC->GetActorLocation(), NPC->GetActorForwardVector()*100.0f, FColor::Red, false, 1.0f, 0, 3.0f);
DrawDebugLine(GetWorld(), NPC->GetActorLocation(), NPC->GetActorRightVector()*100.0f, FColor::Blue, false, 1.0f, 0, 3.0f);
What’s wrong?
Any other way to get the vectors that point forward and to the right always with respect to the pawn’s position and rotation?
Thank you so much!!
1 Like
You’ve drawn the line from the actor location to the origin, roughly. You need to add the vectors to get the destination point
DrawDebugLine(GetWorld(), NPC->GetActorLocation(), NPC->GetActorLocation() + ( NPC->GetActorForwardVector()*100.0f ), FColor::Red, false, 1.0f, 0, 3.0f);
2 Likes
Ivan3z
(Ivan3z)
December 27, 2024, 9:58am
3
Now I think I’m dumb…
Thank you very much for the help @ClockworkOcean
Can I ask one more question?
I’m trying to rotate the vector forward.
float Azimuth=0.0f;
float Elevation=0.0f;
const FVector Direction = UKismetMathLibrary::GetDirectionUnitVector( NPC->GetActorLocation(), Enemy->GetActorLocation());
UKismetMathLibrary::GetAzimuthAndElevation(Direction, NPC->GetActorTransform(), Azimuth, Elevation);
const FVector RotatedForwardVector = UKismetMathLibrary::RotateAngleAxis( NPC->GetActorForwardVector(), -Elevation, NPC->GetActorRightVector() );
However the vector (RotatedForwardVector) does not point where it is supposed (to the enemy).
The pawn always looks at the enemy (It is focused). It’s a problem with the height difference only.
I thought there was a problem with
GetActorForwardVector() & GetActorRightVector()
But your answer shows that they work well.
Maybe I’m doing something wrong?
1 Like
If you want to look at something, then you can just use ‘find look at rotation’?
1 Like
Ivan3z
(Ivan3z)
December 27, 2024, 10:11am
5
I will try it…thanks a lot!!
1 Like