Problem
I have a crosshair in the middle of the screen.
I need to create a lineTrace
that passes straight through this crosshair.
As this is a third person game, I need the line trace to cast through the crosshair
Question
How do I do this
Code sample
#include "GameFramework/PlayerController.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.h"
#include "Camera/PlayerCameraManager.h"
#include "GrabObjects.h"
#include "CollisionQueryParams.h"
#define OUT
//...
// Called every frame
void UGrabObjects::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
//...
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
// Get player viewport
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT PlayerViewPointLocation,
OUT PlayerViewPointRotation
);
// Draw a line from player showing reach
// PlayerViewPointRotation.Vector() is the unit vector
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
DrawDebugLine(
GetWorld(),
PlayerViewPointLocation,
LineTraceEnd,
FColor(0, 255, 0),
0.f,
0,
5.f
);
//...
}
```