• News

• Industries

• Learning & Support

• Community

• Marketplace # Pawn Radar - Issue in getting this done properly

Hi,

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();
{
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.

http://wiki.beyondunreal.com/Legacy:UnrealScript_Vector_Maths#A_vector_that_points_from_A_to_B

Same logic though.

In the diagram A would be GetActorLocation() and B would be ActorItr->GetActorLocation()

``````

FVector CharPositionRelativeToSelf =  GetActorLocation() - ActorItr->GetActorLocation();

``````

So you are actually getting the data for the vector from B to A. Flip your code to B - A as below

``````

FVector CharPositionRelativeToSelf =  ActorItr->GetActorLocation() - GetActorLocation();

``````

And hopefully it will work.

I tried this, and it’s still not working.

In fact, when Yaw = 0 or 180 it’s working as expected, but if yaw is 90 or 270, the Y axis is inverted.

Any hints?

thanks,

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.

I’m sure it’s the rotation Stuff…
In fact when yaw is 0 (North…) it’s working as expected.

it is “RotationAngle.RotateVector(CharPositionRelativeToSelf);” that’s not doing what I understand it should do ^^

I have another approach with Sin & Cos
like

``````

CharPositionRelativeToSelf.X = FMath::Cos(RotationAngle.Yaw) * CharPositionRelativeToSelf.X - FMath::Sin(RotationAngle.Yaw)*CharPositionRelativeToSelf.Y;
CharPositionRelativeToSelf.Y = FMath::Sin(RotationAngle.Yaw) * CharPositionRelativeToSelf.X + FMath::Cos(RotationAngle.Yaw)*CharPositionRelativeToSelf.Y;

``````

I will appreciate if you can share the way you did.

Thanks,

This is my code from a UDK project rewritten to use your variables

``````

FVector Pos = CharPositionRelativeToSelf;
CharPositionRelativeToSelf.X = Pos.VSize() * FMath::Cos( FMath::Atan2(Pos.Y, Pos.X) - RotationAngle.Yaw);
CharPositionRelativeToSelf.Y = Pos.VSize() * FMath::Sin( FMath::Atan2(Pos.Y, Pos.X) - RotationAngle.Yaw);

``````

The math is solid but not tested it in UE4. Its on my todo list but Im still writing movement code at present, haven’t got near the HUD.

Thanks, I will look into that this we.

Here we have the solution:

Here is GeekyPayback code in UE4 format that works!!

``````

FVector Pos = CharPositionRelativeToSelf;
CharPositionRelativeToSelf.X = Pos.Size() * FMath::Cos( FMath::Atan2(Pos.Y, Pos.X) - FMath::DegreesToRadians(RotationAngle.Yaw));
CharPositionRelativeToSelf.Y = Pos.Size() * FMath::Sin( FMath::Atan2(Pos.Y, Pos.X) - FMath::DegreesToRadians(RotationAngle.Yaw));

``````

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);

``````