What is the function mean GetCameraDamageStartLocation() in shootgame sample

Sorry about my rookie. I cant Understand the comment of this source.
/** get the originating location for camera damage */

    FVector GetCameraDamageStartLocation(const FVector& AimDir) const;

what is the CameraDamage?
Any one who can tell me the function how to work ?
and what is the effect of this line,especially ((Instigator->GetActorLocation() - OutStartTrace) | AimDir).

OutStartTrace = OutStartTrace + AimDir * ((Instigator->GetActorLocation() - OutStartTrace) | AimDir);

plz be easily to understand,

this is the function souce:


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 * ((Instigator->GetActorLocation() - OutStartTrace) | AimDir);
	}
	else if (AIPC)
	{
		OutStartTrace = GetMuzzleLocation();
	}

	return OutStartTrace;
}

and this function be used in:


void AShooterWeapon_Instant::FireWeapon()
{
	const int32 RandomSeed = FMath::Rand();
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = GetCurrentSpread();
	const float ConeHalfAngle = FMath::DegreesToRadians(CurrentSpread * 0.5f);

	const FVector AimDir = GetAdjustedAim();
	const FVector StartTrace = GetCameraDamageStartLocation(AimDir);
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, ConeHalfAngle, ConeHalfAngle);
	const FVector EndTrace = StartTrace + ShootDir * InstantConfig.WeaponRange;

	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);

	CurrentFiringSpread = FMath::Min(InstantConfig.FiringSpreadMax, CurrentFiringSpread + InstantConfig.FiringSpreadIncrement);
}

any answer will be appreciated,thx.

There’s a lot going on here, and as you’re saying you’re a rookie, I’ve added some links to all the terms for better understanding.

In short, it seems that GetCameraDamageStartLocation() just finds the location from which to start the line trace when the player fires the weapon. This line trace is done to find out what the player hit with their shot.
This would usually be the center of the player camera in FPS games, and would extend in the general direction in which the player is facing, and be limited to some maximum distance. (Seems like shooter game is also adding some random inaccuracy, but that’s sort of besides the point).

As for the pipe character ("|"), this is (in most programming languages) called a “Bitwise Or” operator, but don’t worry too much about that, because in the Unreal Engine, for Vectors, they are overloading this operator (where operator means anything like multiply, divide, equals etc.) to mean “Calculate Dot Productas stated in the documentation.

thank your answer ,but I want to know

why not use GetPlayerViewPoint(startTraceLocation,UnusedRotation) or get camera location to find the StartTrace.I tried,there are also can make a ray from the camera screen center to aim location ,there are the same effect.

OutStartTrace = OutStartTrace + AimDir * ((Instigator->GetActorLocation() - OutStartTrace) | AimDir);

and this line is difficult to understand.

Ok, it seems what they’re doing there is to find a point outside of the Character’s collision capsule to start the trace from. The reason for this is simply that if you start the trace from the player’s camera location, it will hit the character’s collision component. Naturally you don’t want the character to shoot herself.

As for the implementation, I might very possibly be wrong, but I don’t think it will work as expected. The reason for this is that the amount by which they move from the camera location in the aim direction is only dependent on the distance between the player’s viewpoint (camera location) and the actual player’s collision capsule location, and the aim direction.

I would think a better solution would be to simply add the player to the trace param’s ignore list.

I think a numeric example will be helpful here (working in 2D, but 3D effect is the same):

Suppose you have a character with a capsule component with dimensions (width=100, height=200), and the character is currently at world position (x=300,y=500).
Let’s also say that the camera location is (300,550).

Now, let’s say the player fires in direction (2,-1) relative.

Doing the math gives a new StartTrace Location of (320,540). Which is still within the capsule bounds.

  • OutStartTrace=(300,550)

  • InstigatorLocation=(300,500)

  • AimDir=(2,-1) → Normalised = (0.894…,-0.447…)

  • (InstigatorLocation-OutStartTrace) = (0,-50)

  • (InstigatorLocation-OutStartTrace) dot AimDir = 22.36…

  • AimDir * ((InstigatorLocation-OutStartTrace) dot AimDir) = (20,-10)

  • OutStartTrace + AimDir * ((InstigatorLocation-OutStartTrace) dot AimDir) = (320,540)

Or am I missing something here?