Drawing Debug Lines around Character

Hello :slight_smile:

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. :smiley:

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?

AngleRad is in degrees.
So you’re treating the degrees as radians for “float AngleDeg = FMath::RadiansToDegrees( AngleRad );”, which is pure nonsense.
And then later “FMath::RadiansToDegrees( AngleDeg )” would make no sense even if AngleDeg was actually degrees rather than nonsense.

Oh LoL! Of course. Thank you! :smiley:


float AngleDeg = FMath::RadiansToDegrees( AngleRad );
....RotateAngleAxis( FMath::RadiansToDegrees( AngleDeg ), ... );


I didn’t even see this … Was a remnant from yesterday night’s half-sleeping attempts. Gosh.

Fixed it. Works now.



FColor Color = FColor::Green;
for ( float AngleDeg = 0.f; AngleDeg < 360.f; AngleDeg += 90.f )
{
	FVector TempLocation = TargetLocation - FVector( 0.f, 100.f, 0.f ).RotateAngleAxis( AngleDeg, FVector( 0.f, 0.f, 1.f ) );
	
	DrawDebugLine(
		GetWorld(), TargetLocation, TempLocation, Color, false, 5.f, 0, 2.f
	);
}