133 - Hit Scan Weapons
This commit is contained in:
parent
8681efed44
commit
d6557fb499
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -270,6 +270,12 @@ void ABlasterCharacter::PlayReloadMontage()
|
||||||
case EWeaponType::EWT_RocketLauncher:
|
case EWeaponType::EWT_RocketLauncher:
|
||||||
SectionName = FName("Rifle"); // Todo: create rocket reload montage section
|
SectionName = FName("Rifle"); // Todo: create rocket reload montage section
|
||||||
break;
|
break;
|
||||||
|
case EWeaponType::EWT_Pistol:
|
||||||
|
SectionName = FName("Rifle"); // Todo: create pistol reload montage section
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SectionName = FName("Rifle");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimInstance->Montage_JumpToSection(SectionName);
|
AnimInstance->Montage_JumpToSection(SectionName);
|
||||||
|
|
|
@ -456,4 +456,5 @@ void UCombatComponent::InitializeCarriedAmmo()
|
||||||
{
|
{
|
||||||
CarriedAmmoMap.Emplace(EWeaponType::EWT_AssaultRifle, StartingARAmmo);
|
CarriedAmmoMap.Emplace(EWeaponType::EWT_AssaultRifle, StartingARAmmo);
|
||||||
CarriedAmmoMap.Emplace(EWeaponType::EWT_RocketLauncher, StartingRocketAmmo);
|
CarriedAmmoMap.Emplace(EWeaponType::EWT_RocketLauncher, StartingRocketAmmo);
|
||||||
|
CarriedAmmoMap.Emplace(EWeaponType::EWT_Pistol, StartingPistolAmmo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,9 @@ private:
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
int32 StartingRocketAmmo = 8;
|
int32 StartingRocketAmmo = 8;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
int32 StartingPistolAmmo = 15;
|
||||||
|
|
||||||
void InitializeCarriedAmmo();
|
void InitializeCarriedAmmo();
|
||||||
|
|
||||||
UPROPERTY(ReplicatedUsing=OnRep_CombatState)
|
UPROPERTY(ReplicatedUsing=OnRep_CombatState)
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "HitScanWeapon.h"
|
||||||
|
|
||||||
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
|
#include "Engine/SkeletalMeshSocket.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
void AHitScanWeapon::Fire(const FVector& HitTarget)
|
||||||
|
{
|
||||||
|
Super::Fire(HitTarget);
|
||||||
|
|
||||||
|
APawn* OwnerPawn = Cast<APawn>(GetOwner());
|
||||||
|
if (OwnerPawn == nullptr) return;
|
||||||
|
AController* InstigatorController = OwnerPawn->GetController();
|
||||||
|
|
||||||
|
const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash");
|
||||||
|
if (MuzzleFlashSocket && InstigatorController)
|
||||||
|
{
|
||||||
|
FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh());
|
||||||
|
FVector Start = SocketTransform.GetLocation();
|
||||||
|
FVector End = Start + (HitTarget - Start) * 1.25f;
|
||||||
|
|
||||||
|
FHitResult FireHit;
|
||||||
|
UWorld* World = GetWorld();
|
||||||
|
if (World)
|
||||||
|
{
|
||||||
|
World->LineTraceSingleByChannel(
|
||||||
|
FireHit,
|
||||||
|
Start,
|
||||||
|
End,
|
||||||
|
ECC_Visibility
|
||||||
|
);
|
||||||
|
if (FireHit.bBlockingHit)
|
||||||
|
{
|
||||||
|
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor());
|
||||||
|
if (BlasterCharacter)
|
||||||
|
{
|
||||||
|
if (HasAuthority())
|
||||||
|
{
|
||||||
|
UGameplayStatics::ApplyDamage(
|
||||||
|
BlasterCharacter,
|
||||||
|
Damage,
|
||||||
|
InstigatorController,
|
||||||
|
this,
|
||||||
|
UDamageType::StaticClass()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImpactParticles)
|
||||||
|
{
|
||||||
|
UGameplayStatics::SpawnEmitterAtLocation(
|
||||||
|
World,
|
||||||
|
ImpactParticles,
|
||||||
|
FireHit.ImpactPoint,
|
||||||
|
FireHit.ImpactNormal.Rotation()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Weapon.h"
|
||||||
|
#include "HitScanWeapon.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class BLASTER_API AHitScanWeapon : public AWeapon
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void Fire(const FVector& HitTarget) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float Damage = 20.f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class UParticleSystem* ImpactParticles;
|
||||||
|
};
|
|
@ -89,25 +89,25 @@ protected:
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere, Category="Weapon Properties")
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
||||||
USkeletalMeshComponent* WeaponMesh;
|
USkeletalMeshComponent* WeaponMesh;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, Category="Weapon Properties")
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
||||||
class USphereComponent* AreaSphere;
|
class USphereComponent* AreaSphere;
|
||||||
|
|
||||||
UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category="Weapon Properties")
|
UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category = "Weapon Properties")
|
||||||
EWeaponState WeaponState;
|
EWeaponState WeaponState;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnRep_WeaponState();
|
void OnRep_WeaponState();
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, Category="Weapon Properties")
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
||||||
class UWidgetComponent* PickupWidget;
|
class UWidgetComponent* PickupWidget;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category= "Weapon Properties")
|
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
||||||
class UAnimationAsset* FireAnimation;
|
class UAnimationAsset* FireAnimation;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category= "Weapon Properties")
|
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
||||||
TSubclassOf<class ACasing> CasingClass;
|
TSubclassOf<class ACasing> CasingClass;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, ReplicatedUsing=OnRep_Ammo)
|
UPROPERTY(EditAnywhere, ReplicatedUsing=OnRep_Ammo)
|
||||||
|
|
|
@ -5,6 +5,7 @@ enum class EWeaponType: uint8
|
||||||
{
|
{
|
||||||
EWT_AssaultRifle UMETA(DisplayName="Assault Rifle"),
|
EWT_AssaultRifle UMETA(DisplayName="Assault Rifle"),
|
||||||
EWT_RocketLauncher UMETA(DisplayName="Rocket Launcher"),
|
EWT_RocketLauncher UMETA(DisplayName="Rocket Launcher"),
|
||||||
|
EWT_Pistol UMETA(DisplayName="Pistol"),
|
||||||
|
|
||||||
EWT_MAX UMETA(DisplayName="DefaultMAX")
|
EWT_MAX UMETA(DisplayName="DefaultMAX")
|
||||||
};
|
};
|
Loading…
Reference in New Issue