78 - Shell Physics
This commit is contained in:
parent
58df613558
commit
490af86ef1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,18 +3,42 @@
|
||||||
|
|
||||||
#include "Casing.h"
|
#include "Casing.h"
|
||||||
|
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Sound/SoundCue.h"
|
||||||
|
|
||||||
ACasing::ACasing()
|
ACasing::ACasing()
|
||||||
{
|
{
|
||||||
PrimaryActorTick.bCanEverTick = false;
|
PrimaryActorTick.bCanEverTick = false;
|
||||||
|
|
||||||
|
ShellEjectionImpulseMin = 8.f;
|
||||||
|
ShellEjectionImpulseMax = 12.f;
|
||||||
CasingMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CasingMesh"));
|
CasingMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CasingMesh"));
|
||||||
|
CasingMesh->SetCollisionResponseToChannel(ECC_Camera, ECR_Ignore);
|
||||||
|
CasingMesh->SetSimulatePhysics(true);
|
||||||
|
CasingMesh->SetEnableGravity(true);
|
||||||
|
CasingMesh->SetNotifyRigidBodyCollision(true);
|
||||||
SetRootComponent(CasingMesh);
|
SetRootComponent(CasingMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACasing::BeginPlay()
|
void ACasing::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
CasingMesh->OnComponentHit.AddDynamic(this, &ACasing::OnHit);
|
||||||
|
CasingMesh->AddImpulse(GetActorForwardVector() * FMath::RandRange(ShellEjectionImpulseMin, ShellEjectionImpulseMax));
|
||||||
|
|
||||||
|
SetLifeSpan(5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACasing::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||||
|
{
|
||||||
|
if (ShellSound)
|
||||||
|
{
|
||||||
|
UGameplayStatics::PlaySoundAtLocation(this, ShellSound, GetActorLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable hit event so that sound won't play multiple times
|
||||||
|
CasingMesh->SetNotifyRigidBodyCollision(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,21 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UStaticMeshComponent* CasingMesh;
|
UStaticMeshComponent* CasingMesh;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float ShellEjectionImpulseMin;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float ShellEjectionImpulseMax;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class USoundCue* ShellSound;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue