I’m trying to set a radar to show some actor around your character. I fail in getting the “orientation” of the pawn versus self to be done properly.
here is the code used:
for (TActorIterator<ACharacter> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
FVector CharPositionRelativeToSelf = GetActorLocation() - ActorItr->GetActorLocation();
float distance = CharPositionRelativeToSelf.Size();
if (distance < RadarRadius)
{
FRotator RotationAngle = GetActorRotation();
//ScalePosition in Map scale
CharPositionRelativeToSelf.X *= ScaleX;
CharPositionRelativeToSelf.Y *= ScaleY;
//Rotate the Position of Rotation Angle
CharPositionRelativeToSelf = RotationAngle.RotateVector(CharPositionRelativeToSelf);
//Draw the Pawn Plot!
}
}
I know the Yaw can have 90° shift issue as 0 = East and not North, but I will correct that later on except if that’s the errors but I doubt.
For the moment, depanding of my RotationAngle, the radar act correctly or not.
As the consequence, the Y or X value move in the opposite way. I means when the pawn is in front of me, the radar shows it in the back.
The only thing I can think of is disable all your rotation angle stuff. Check that the position is correct with just a map that always faces north.
If that works you know the problem is now with how you are rotating the objects around the compass, rather than figuring out where they are relative to the player.
If positions look correct with a compass that just faces north I’ll stick some code up showing the math for how I did my map stuff.
More, with this I was able to understand what was wrong in my calculation, I forgot to invert the Yaw before rotating the vector.
Here is the code if others are interested in setting a minimap
FRotator RotationAngle = GetActorRotation();
//Fix 90° offset so 0 is North and not East
RotationAngle.Yaw += 90;
//Need to invert the angle to apply the rigth angle to the vector
RotationAngle.Yaw*=-1;
//ScalePosition in Map scale
CharPositionRelativeToSelf.X *= ScaleX;
CharPositionRelativeToSelf.Y *= ScaleY;
//Rotate the Position of Rotation Angle
CharPositionRelativeToSelf = RotationAngle.RotateVector(CharPositionRelativeToSelf);