I have a vehicle that has several weapon turret actors attached.
I am trying to represent those weapon turret actors onto a HUD Menu that is supposed to display a top down of the vehicle, and icons representing its turrets at the turret positions.
The problem is that the turret position icons(the whole group of them not each individual icon) turn to match the vehicles facing. I need the group to always be oriented towards the top of the screen.
jwatte’s last suggestion has lead me to getting something that half works:
FVector WorldNorth = FVector(1,0,0);
FVector CompDIR = (Center - CompPos).GetSafeNormal();
float OffsetAngle = FMath::RadiansToDegrees(acosf(FVector:: DotProduct(CompDIR, WorldNorth)));
FVector Up = FVector(0,0,1);
OutVector = (CompPos - Center).RotateAngleAxis(OffsetAngle, Up);
OutVector += Center;
The resulting OffsetAngle is always positive, climbs to 180 as the vehicle turns south, then falls back to 0 when turning to face north again. Regardless of east or west facing.
The turret icon, will follow the rotation of the vehicle when it is turning east, but remain fixed to the top of the screen(this is what I want!) when the vehicle is facing west.
Now I just need to get it to do that for the east side as well…
I just added a check to see what side of the ship WorldNorth was on and then multiplied the OffsetAngle by -1 or 1 depending on the result.
BUUUT… it only works for the one turret that is dead forward and center of the vehicles location.
The icons for turrets that are forward and left or right are pushed to the center, while anything behind is still following the vehicle’s rotation.