77 - Bullet Shells

This commit is contained in:
Kingsmedia 2022-05-05 15:49:24 +02:00
parent ffa9bfc84c
commit 58df613558
7 changed files with 67 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Casing.h"
ACasing::ACasing()
{
PrimaryActorTick.bCanEverTick = false;
CasingMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CasingMesh"));
SetRootComponent(CasingMesh);
}
void ACasing::BeginPlay()
{
Super::BeginPlay();
}

View File

@ -0,0 +1,24 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Casing.generated.h"
UCLASS()
class BLASTER_API ACasing : public AActor
{
GENERATED_BODY()
public:
ACasing();
protected:
virtual void BeginPlay() override;
private:
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* CasingMesh;
};

View File

@ -3,9 +3,11 @@
#include "Weapon.h"
#include "Casing.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Components/SphereComponent.h"
#include "Components/WidgetComponent.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Net/UnrealNetwork.h"
AWeapon::AWeapon()
@ -115,4 +117,22 @@ void AWeapon::Fire(const FVector& HitTarget)
{
WeaponMesh->PlayAnimation(FireAnimation, false);
}
if (CasingClass)
{
const USkeletalMeshSocket* AmmoEjectSocket = WeaponMesh->GetSocketByName(FName("AmmoEject"));
if (AmmoEjectSocket)
{
FTransform SocketTransform = AmmoEjectSocket->GetSocketTransform(WeaponMesh);
UWorld* World = GetWorld();
if (World)
{
World->SpawnActor<ACasing>(
CasingClass,
SocketTransform.GetLocation(),
SocketTransform.GetRotation().Rotator()
);
}
}
}
}

View File

@ -66,6 +66,9 @@ private:
UPROPERTY(EditAnywhere, Category= "Weapon Properties")
class UAnimationAsset* FireAnimation;
UPROPERTY(EditAnywhere, Category= "Weapon Properties")
TSubclassOf<class ACasing> CasingClass;
public:
void SetWeaponState(EWeaponState State);
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }