Ray cast End point problem

Hey guys, I need to shoot a ray cast from the start to where the pawn is looking at.

const FVector StartServer = myPC->GetFocalLocation();
const FVector EndServer = StartServer + GetControlRotation().Vector() * 1000;

Doens’t help.

i have a collision component sitting at the nose of the turret. I’m thinking if I get it’s forward vector, that can be the the end.

Any hints to how I can get my Pawn to shoot a ray cast from the Start point (The nose of the turret) to the end point, 2500 units away to where the Pawn is looking.

Cheers.

Video Youtube showing problem

I think the problem is that you’re using the Controller rotation, and the controller’s rotation is not updated based on the camera.
You will require some way of getting the turret location. I would suggest adding a socket to the turret mesh and then getting that socket’s location.

e.g. in your pawn:

FVector startLocPawn = GetPawnViewLocation();
FRotator viewRotPawn = GetViewRotation().GetNormalized();
FVector endLocPawn = startLocPawn + viewRotPawn.Vector() * 2500.0f;
FVector startLocTurret = TurretMeshComp->GetSocketLocation(TEXT("YourSocketName"));

 FCollisionQueryParams cqp = FCollisionQueryParams(FName(TEXT("trace")), true, this);
cqp.bTraceComplex = true;
cqp.bTraceAsyncScene = true;
cqp.bReturnPhysicalMaterial = false;
 
 //Re-initialize hit info
 FHitResult hitInfo(ForceInit);
     
 //call GetWorld() from within an actor extending class
 GetWorld()->LineTraceSingle(
     hitInfo,        //result
     startLocTurret,    //start
     endLocPawn, //end
     ECC_Pawn, //collision channel
     cqp
 );