Hello Devs,
I am trying to trace 4 debug lines, each of them starting from each corner of the character’s view point (game is a FPS) and ending at the middle of the screen, making a type of crosshair. Problem is, when I look up or down, the trace lines are moving from their respective corners and by looking directly upward, the lines are all aligned horizontally, simulating one line going from the left to right in the middle of the screen. I understand why but I cannot find a solution for it.
Here’s the code :
// Get the aim starting and ending positions
FVector AimStart;
FRotator AimRotation;
GetActorEyesViewPoint(AimStart, AimRotation);
FVector AimEnd = AimStart + AimRotation.Vector() * ScanDistance;
// Trace the line for scan
DrawDebugLine(GetWorld(), AimStart + AimRotation.Vector().UpVector * ScanOffset1 + GetActorRightVector() * ScanOffset1, AimEnd + AimRotation.Vector().UpVector * ScanOffset2 + GetActorRightVector() * ScanOffset2, FColor::Cyan); // Top right
DrawDebugLine(GetWorld(), AimStart - AimRotation.Vector().UpVector * ScanOffset1 + GetActorRightVector() * ScanOffset1, AimEnd - AimRotation.Vector().UpVector * ScanOffset2 + GetActorRightVector() * ScanOffset2, FColor::Cyan); // Bottom right
DrawDebugLine(GetWorld(), AimStart - AimRotation.Vector().UpVector * ScanOffset1 - GetActorRightVector() * ScanOffset1, AimEnd - AimRotation.Vector().UpVector * ScanOffset2 - GetActorRightVector() * ScanOffset2, FColor::Cyan); // Bottom left
DrawDebugLine(GetWorld(), AimStart + AimRotation.Vector().UpVector * ScanOffset1 - GetActorRightVector() * ScanOffset1, AimEnd + AimRotation.Vector().UpVector * ScanOffset2 - GetActorRightVector() * ScanOffset2, FColor::Cyan); // Top left
To explain further what is happening, when looking upward the “AimRotation.Vector()” isn’t in the Z direction but is going behind the character and it’s UpVector is 0.
What I would like to have is 4 trace lines that never moves from their respective corners.
Any help is much appreciated, as always, cheers!