Hello
I want to draw some debug lines around a character. I thought that is a quick and easy task. But I spend like 3+ hours yesterday trying to figure out what I do wrong before I finally went to bed. I’m not really good at math, but I think I got the basics of whats going on. Or have I …? Not sure anymore.
First I thought I just subtract a target vector for my line’s end point (100 units) and rotate it by the required angle on the Z axis:
FVector TempLocation = TargetLocation - FVector( 0.f, 100.f, 0.f ).RotateAngleAxis( FMath::RadiansToDegrees( AngleDeg ), FVector( 0.f, 0.f, 1.f ) );
This works, but the lines are not where I expected them to be. I want the lines to be at 12, 3, 6 and 9 o’clock. But they are … somewhere else:
Then I thought I’d try a simple triangle formula:
FVector TempLocation = TargetLocation - FVector( FMath::Cos( AngleRad ) * 100.f, FMath::Sin( AngleRad ) * 100.f, 0 );
This works too, but the lines are somewhere else again:
FVector TargetLocation = OtherActor->GetActorLocation();
for ( float AngleRad = 0.f; AngleRad < 360.f; AngleRad += 90.f )
{
float AngleDeg = FMath::RadiansToDegrees( AngleRad );
FColor Color = FColor::Green;
//FVector TempLocation = TargetLocation - FVector( 0.f, 100.f, 0.f ).RotateAngleAxis( FMath::RadiansToDegrees( AngleDeg ), FVector( 0.f, 0.f, 1.f ) );
FVector TempLocation = TargetLocation - FVector( FMath::Cos( AngleRad ) * 100.f, FMath::Sin( AngleRad ) * 100.f, 0 );
DrawDebugLine(
GetWorld(), TargetLocation, TempLocation, Color, false, 5.f, 0, 2.f
);
}
What am I missing?