The problem is in concept very simple.
I have and Crosshair. By default is drawed exactly in center of the screen.
I moved crosshair 50 pixels to the bottom.
Now is the tricky part. How to make trace, so it will end exactly at the crosshair position ?
So far I have been using this:
FVector Origin = GetCastingLocation();
const FVector ShootDir = GetCameraAim();
const FVector StartTrace = GetCameraDamageStarLocation(ShootDir);// - AdjustVec;
//const FVector StartTrace = Origin;
const FVector WeapRange = FVector(10000.0f, 10000.0f, 10000.0f);
const FVector EndTrace = (StartTrace + ShootDir * WeapRange);//- AdjustVec * 1.0f;
FHitResult Impact = AbilityTrace(StartTrace, EndTrace);
DrawDebugLine(Instigator->GetWorld(), StartTrace, EndTrace, FColor::Black, true, 10.0f, 0.0f, 1.0f);
if(Impact.GetActor())
{
//0-1 range
const FVector AdjustedDir = (Impact.ImpactPoint - Origin).SafeNormal();
DrawDebugLine(Instigator->GetWorld(), Origin, Impact.ImpactPoint, FColor::Red, true, 10.0f, 0.0f, 1.0f);
}
FVector ARPGAbility::GetCastingLocation()
{
USkeletalMeshComponent* UseMesh = GetWeaponMesh();
return UseMesh->GetSocketLocation("WeaponPoint");
}
FVector ARPGAbility::GetCameraDamageStarLocation(const FVector& AimDir) const
{
ARPGPlayerController* PC = (MyPawn != NULL) ? Cast(MyPawn->Controller) : NULL;
FVector OutStartTrace = FVector::ZeroVector;
if(PC)
{
FRotator UnusedRot;
PC->GetPlayerViewPoint(OutStartTrace, UnusedRot);
OutStartTrace = OutStartTrace + AimDir * ((Instigator->GetActorLocation() - OutStartTrace) | AimDir);
}
return OutStartTrace;
}
It’s more or less the code from shooter example. It works perfectly fine if I leave crosshair in center of the screen. But adjusting vectors so they will end up exactly at new crosshair position proved to be far more tricky than I first thought.
If anyone have any idea or direction, where I should start looking to solve it it would be very much appreciated.
If anyone wonder “Why the hell this guy want to move crosshair to random spot on screen, instead of leaving in center”. The answer is that by default my TPP camera is, quite high (as in comparison to other TPP games at least), and while for now it’s doing it’s job it’s not that accurate on closer distances.