150 - Spawning Grenades

This commit is contained in:
Kingsmedia 2022-05-22 14:11:35 +02:00
parent d114ceb1fb
commit 5c1967bdaa
10 changed files with 30 additions and 7 deletions

View File

@ -315,6 +315,25 @@ void UCombatComponent::ThrowGrenadeFinished()
void UCombatComponent::LaunchGrenade()
{
ShowAttachedGrenade(false);
if (Character && Character->HasAuthority() && GrenadeClass && Character->GetAttachedGrenade())
{
const FVector StartingLocation = Character->GetAttachedGrenade()->GetComponentLocation();
FVector ToTarget = HitTarget - StartingLocation;
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = Character;
SpawnParams.Instigator = Character;
UWorld* World = GetWorld();
if (World)
{
World->SpawnActor<AProjectile>(
GrenadeClass,
StartingLocation + 10.f,
ToTarget.Rotation(),
SpawnParams
);
}
}
}
void UCombatComponent::OnRep_CombatState()
@ -362,7 +381,7 @@ int32 UCombatComponent::AmountToReload()
void UCombatComponent::ThrowGrenade()
{
if (CombatState != ECombatState::ECS_Unoccupied) return;
if (CombatState != ECombatState::ECS_Unoccupied || EquippedWeapon == nullptr) return;
CombatState = ECombatState::ECS_ThrowingGrenade;
if (Character)
{

View File

@ -7,6 +7,7 @@
#include "Blaster/Types/CombatState.h"
#include "Blaster/Weapon/WeaponTypes.h"
#include "Components/ActorComponent.h"
#include "Blaster/Weapon/Projectile.h"
#include "CombatComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
@ -71,6 +72,9 @@ protected:
UFUNCTION(Server, Reliable)
void ServerThrowGrenade();
UPROPERTY(EditAnywhere)
TSubclassOf<class AProjectile> GrenadeClass;
void DropEquippedWeapon();
void AttachActorToRightHand(AActor* ActorToAttach);
void AttachActorToLeftHand(AActor* ActorToAttach);