コード例 #1
0
void ASWeaponInstant::FireWeapon()
{
    const FVector AimDir = GetAdjustedAim();
    const FVector CameraPos = GetCameraDamageStartLocation(AimDir);
    const FVector EndPos = CameraPos + (AimDir * WeaponRange);

    /* Check for impact by tracing from the camera position */
    FHitResult Impact = WeaponTrace(CameraPos, EndPos);

    const FVector MuzzleOrigin = GetMuzzleLocation();

    FVector AdjustedAimDir = AimDir;
    if (Impact.bBlockingHit)
    {
        /* Adjust the shoot direction to hit at the crosshair. */
        AdjustedAimDir = (Impact.ImpactPoint - MuzzleOrigin).GetSafeNormal();

        /* Re-trace with the new aim direction coming out of the weapon muzzle */
        Impact = WeaponTrace(MuzzleOrigin, MuzzleOrigin + (AdjustedAimDir * WeaponRange));
    }
    else
    {
        /* Use the maximum distance as the adjust direction */
        Impact.ImpactPoint = FVector_NetQuantize(EndPos);
    }

    ProcessInstantHit(Impact, MuzzleOrigin, AdjustedAimDir);
}
コード例 #2
0
void ASWeaponInstant::FireWeapon()
{	
	const FVector AimDir = GetAdjustedAim();
	const FVector StartPos = GetCameraDamageStartLocation(AimDir);
	const FVector EndPos = StartPos + (AimDir * WeaponRange);

	const FHitResult Impact = WeaponTrace(StartPos, EndPos);
	ProcessInstantHit(Impact, StartPos, AimDir);
}
コード例 #3
0
void AWeapon::Instant_Fire()
{

		const int32 RandomSeed = FMath::Rand();
		FRandomStream WeaponRandomStream(RandomSeed);
		const float CurrentSpread = WeaponConfig.WeaponSpread;
		const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
		const FVector AimDir = WeaponMesh->GetSocketRotation("MF").Vector();
		const FVector StartTrace = WeaponMesh->GetSocketLocation("MF");
		const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);
		const FVector EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;
		const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);

		ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);


}
コード例 #4
0
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);
}