Implemented ammo collection + random bullet spread
This commit is contained in:
parent
b468f703f9
commit
bc9c73df78
@ -4,9 +4,9 @@
|
|||||||
#include "Player/LMPlayer.h"
|
#include "Player/LMPlayer.h"
|
||||||
|
|
||||||
#include "KismetTraceUtils.h"
|
#include "KismetTraceUtils.h"
|
||||||
#include "LMBulletInfo.h"
|
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Ammo/LMAmmo.h"
|
#include "Ammo/LMAmmo.h"
|
||||||
|
#include "Player/LMBulletInfo.h"
|
||||||
#include "Weapon/LMWeaponManager.h"
|
#include "Weapon/LMWeaponManager.h"
|
||||||
|
|
||||||
ALMPlayer::ALMPlayer()
|
ALMPlayer::ALMPlayer()
|
||||||
@ -21,6 +21,8 @@ ALMPlayer::ALMPlayer()
|
|||||||
|
|
||||||
ArmsMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Arms Mesh"));
|
ArmsMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Arms Mesh"));
|
||||||
ArmsMesh->SetupAttachment(Camera);
|
ArmsMesh->SetupAttachment(Camera);
|
||||||
|
|
||||||
|
SpreadStream = FRandomStream(FMath::Rand());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
@ -59,10 +61,20 @@ void ALMPlayer::PlayAnimation(UAnimMontage* Animation)
|
|||||||
|
|
||||||
void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
|
void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
|
||||||
{
|
{
|
||||||
FVector EndLocation = Settings.Origin + (Settings.Direction * Settings.MaxDistance);
|
FVector EndLocation;
|
||||||
TArray<FHitResult> Hits = TArray<FHitResult>();
|
FVector ShotVector;
|
||||||
GetWorld()->LineTraceMultiByChannel(Hits, Settings.Origin, EndLocation, ECC_Camera);
|
FHitResult OutHit = FHitResult();
|
||||||
DrawDebugLineTraceMulti(GetWorld(), Settings.Origin, EndLocation, EDrawDebugTrace::ForDuration, Hits.Num() > 0, Hits, FColor::Green, FColor::Red, 10.f);
|
|
||||||
|
DrawDebugLine(GetWorld(), Settings.Origin, Settings.Origin + (Settings.Direction * Settings.MaxDistance), FColor::Blue, false, 2.f);
|
||||||
|
|
||||||
|
for (int Shots = 0; Shots < Settings.BulletCount; Shots++)
|
||||||
|
{
|
||||||
|
ShotVector = UKismetMathLibrary::RandomUnitVectorInConeInDegreesFromStream(SpreadStream, Settings.Direction, Settings.Spread);
|
||||||
|
EndLocation = Settings.Origin + (ShotVector * Settings.MaxDistance);
|
||||||
|
|
||||||
|
const bool HasHit = GetWorld()->LineTraceSingleByChannel(OutHit, Settings.Origin, EndLocation, ECC_Camera);
|
||||||
|
DrawDebugLineTraceSingle(GetWorld(), Settings.Origin, EndLocation, EDrawDebugTrace::ForDuration, HasHit, OutHit, FColor::Green, FColor::Red, 2.f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FVector ALMPlayer::GetWeaponFiringOrigin() const
|
FVector ALMPlayer::GetWeaponFiringOrigin() const
|
||||||
|
@ -18,7 +18,7 @@ void ALMShotgun::PrimaryFire()
|
|||||||
if (!Player)
|
if (!Player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PlaySound(Data.FireSound);
|
PlaySound(FireSound);
|
||||||
PlayAnimation(PrimaryFireAnimation);
|
PlayAnimation(PrimaryFireAnimation);
|
||||||
|
|
||||||
FVector Origin = Player->GetWeaponFiringOrigin();
|
FVector Origin = Player->GetWeaponFiringOrigin();
|
||||||
|
@ -68,7 +68,20 @@ void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount)
|
|||||||
FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType);
|
FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType);
|
||||||
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug);
|
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug);
|
||||||
|
|
||||||
|
if (AmmoData.Contains(AmmoType))
|
||||||
|
{
|
||||||
|
AmmoData[AmmoType].AddAmmo(AmmoCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const FString Warning = FString::Printf(TEXT("Ammo type %i not found"), AmmoType);
|
||||||
|
GEngine->AddOnScreenDebugMessage(1, 2.f, FColor::Orange, Warning);
|
||||||
|
|
||||||
|
FLMAmmoData Data = FLMAmmoData();
|
||||||
|
Data.AmmoType = AmmoType;
|
||||||
|
Data.AmmoCount = AmmoCount;
|
||||||
|
AmmoData[AmmoType] = Data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULMWeaponManager::Fire()
|
void ULMWeaponManager::Fire()
|
||||||
|
Reference in New Issue
Block a user