Linetrace starts correct, then

When I first spawn in and press my line trace button it is good, it line traces right in front of me, but if I rotate my camera around a bit and then try line tracing, all of a sudden it is no longer line tracing in front of me, does anyone know why this is happening?

LineTrace

	FVector Start = PlayerCamera->GetComponentLocation();
	FVector End = PlayerCamera->GetForwardVector() * 1500.f;
	FCollisionQueryParams Params;
	Params.AddIgnoredActor(this);
	DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0, 1), true, 10.f, 2, 20);
	return GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECollisionChannel::ECC_Camera, Params);

I think you need to

End := Start + End

2 Likes

this fix’s it, but why? isn’t the forward vector always in front of it correct? Why would it need the start location added to it?

You need to add the forward vector onto the camera location, otherwise it’s just floating in space ( over the origin ) :slight_smile:

1 Like

ah, is there some reason it is slightly off centered? I added a cross hair to see how accurate it was, and it is slightly up and to the left of center for some reason.

Is the crosshair definitely in the center?

yep anchored center in the widget with 0 on position and alignment

sorry I’m an idiot, forgot to center the box it needs alignment, it is centered now, and it is centered

1 Like