MCPcopy Create free account
hub / github.com/DruidMech/MultiplayerCourseBlasterGame / Fire

Method Fire

Source/Blaster/Weapon/ProjectileWeapon.cpp:8–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include "Projectile.h"
7
8void AProjectileWeapon::Fire(const FVector& HitTarget)
9{
10 Super::Fire(HitTarget);
11
12 APawn* InstigatorPawn = Cast<APawn>(GetOwner());
13 const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName(FName("MuzzleFlash"));
14 UWorld* World = GetWorld();
15 if (MuzzleFlashSocket && World)
16 {
17 FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh());
18 // From muzzle flash socket to hit location from TraceUnderCrosshairs
19 FVector ToTarget = HitTarget - SocketTransform.GetLocation();
20 FRotator TargetRotation = ToTarget.Rotation();
21
22 FActorSpawnParameters SpawnParams;
23 SpawnParams.Owner = GetOwner();
24 SpawnParams.Instigator = InstigatorPawn;
25
26 AProjectile* SpawnedProjectile = nullptr;
27 if (bUseServerSideRewind)
28 {
29 if (InstigatorPawn->HasAuthority()) // server
30 {
31 if (InstigatorPawn->IsLocallyControlled()) // server, host - use replicated projectile
32 {
33 SpawnedProjectile = World->SpawnActor<AProjectile>(ProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
34 SpawnedProjectile->bUseServerSideRewind = false;
35 SpawnedProjectile->Damage = Damage;
36 SpawnedProjectile->HeadShotDamage = HeadShotDamage;
37 }
38 else // server, not locally controlled - spawn non-replicated projectile, SSR
39 {
40 SpawnedProjectile = World->SpawnActor<AProjectile>(ServerSideRewindProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
41 SpawnedProjectile->bUseServerSideRewind = true;
42 }
43 }
44 else // client, using SSR
45 {
46 if (InstigatorPawn->IsLocallyControlled()) // client, locally controlled - spawn non-replicated projectile, use SSR
47 {
48 SpawnedProjectile = World->SpawnActor<AProjectile>(ServerSideRewindProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
49 SpawnedProjectile->bUseServerSideRewind = true;
50 SpawnedProjectile->TraceStart = SocketTransform.GetLocation();
51 SpawnedProjectile->InitialVelocity = SpawnedProjectile->GetActorForwardVector() * SpawnedProjectile->InitialSpeed;
52 }
53 else // client, not locally controlled - spawn non-replicated projectile, no SSR
54 {
55 SpawnedProjectile = World->SpawnActor<AProjectile>(ServerSideRewindProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
56 SpawnedProjectile->bUseServerSideRewind = false;
57 }
58 }
59 }
60 else // weapon not using SSR
61 {
62 if (InstigatorPawn->HasAuthority())
63 {
64 SpawnedProjectile = World->SpawnActor<AProjectile>(ProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
65 SpawnedProjectile->bUseServerSideRewind = false;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected