Download

ShooterGame: is GetCameraDamageStartLocation doing something useful?

Hi, what is the purpose of GetCameraDamageStartLocation(), ShooterWeapon.cpp#715 in the Shooter Game sample (the clause for players in particular)? My reading is that it is getting a location at eye level when the player is aiming horizontally, and then curving it towards capsule center as they pitch up or down. Why would that be necessary? And it doesn’t seem like what the nearby comment is referring to about adjusting for obstructions, so maybe I am reading it wrong?

    FVector AShooterWeapon::GetCameraDamageStartLocation(const FVector& AimDir) const
    {
    	AShooterPlayerController* PC = MyPawn ? Cast<AShooterPlayerController>(MyPawn->Controller) : NULL;
    	AShooterAIController* AIPC = MyPawn ? Cast<AShooterAIController>(MyPawn->Controller) : NULL;
    	FVector OutStartTrace = FVector::ZeroVector;

    	if (PC)
    	{
    		// use player's camera
    		FRotator UnusedRot;
    		PC->GetPlayerViewPoint(OutStartTrace, UnusedRot);

    		// Adjust trace so there is nothing blocking the ray between the camera and the pawn, and calculate distance from adjusted start
    		OutStartTrace = OutStartTrace + AimDir * ((GetInstigator()->GetActorLocation() - OutStartTrace) | AimDir);
    	}
    	else if (AIPC)
    	{
    		OutStartTrace = GetMuzzleLocation();
    	}

    	return OutStartTrace;
    }