132 - Rocket Movement Component

This commit is contained in:
Kingsmedia 2022-05-19 11:10:41 +02:00
parent b247adc32d
commit 8681efed44
12 changed files with 70 additions and 8 deletions

View File

@ -267,6 +267,9 @@ void ABlasterCharacter::PlayReloadMontage()
case EWeaponType::EWT_AssaultRifle: case EWeaponType::EWT_AssaultRifle:
SectionName = FName("Rifle"); SectionName = FName("Rifle");
break; break;
case EWeaponType::EWT_RocketLauncher:
SectionName = FName("Rifle"); // Todo: create rocket reload montage section
break;
} }
AnimInstance->Montage_JumpToSection(SectionName); AnimInstance->Montage_JumpToSection(SectionName);

View File

@ -4,9 +4,7 @@
#include "Projectile.h" #include "Projectile.h"
#include "Blaster/Blaster.h" #include "Blaster/Blaster.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Components/BoxComponent.h" #include "Components/BoxComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Sound/SoundCue.h" #include "Sound/SoundCue.h"
@ -23,9 +21,6 @@ AProjectile::AProjectile()
CollisionBox->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); CollisionBox->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
CollisionBox->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block); CollisionBox->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
CollisionBox->SetCollisionResponseToChannel(ECC_SkeletalMesh, ECR_Block); CollisionBox->SetCollisionResponseToChannel(ECC_SkeletalMesh, ECR_Block);
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->bRotationFollowsVelocity = true;
} }
void AProjectile::BeginPlay() void AProjectile::BeginPlay()

View File

@ -35,11 +35,11 @@ protected:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
class UBoxComponent* CollisionBox; class UBoxComponent* CollisionBox;
private:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
class UProjectileMovementComponent* ProjectileMovementComponent; class UProjectileMovementComponent* ProjectileMovementComponent;
private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
class UParticleSystem* Tracer; class UParticleSystem* Tracer;

View File

@ -4,8 +4,16 @@
#include "ProjectileBullet.h" #include "ProjectileBullet.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
AProjectileBullet::AProjectileBullet()
{
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->bRotationFollowsVelocity = true;
ProjectileMovementComponent->SetIsReplicated(true);
}
void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{ {
ACharacter* OwnerCharacter = Cast<ACharacter>(GetOwner()); ACharacter* OwnerCharacter = Cast<ACharacter>(GetOwner());

View File

@ -14,6 +14,10 @@ class BLASTER_API AProjectileBullet : public AProjectile
{ {
GENERATED_BODY() GENERATED_BODY()
public:
AProjectileBullet();
protected: protected:
virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override; virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override;

View File

@ -6,6 +6,7 @@
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "NiagaraFunctionLibrary.h" #include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h" #include "NiagaraComponent.h"
#include "RocketMovementComponent.h"
#include "Components/AudioComponent.h" #include "Components/AudioComponent.h"
#include "Components/BoxComponent.h" #include "Components/BoxComponent.h"
#include "Sound/SoundCue.h" #include "Sound/SoundCue.h"
@ -15,6 +16,10 @@ AProjectileRocket::AProjectileRocket()
RocketMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Rocket Mesh")); RocketMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Rocket Mesh"));
RocketMesh->SetupAttachment(RootComponent); RocketMesh->SetupAttachment(RootComponent);
RocketMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); RocketMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
RocketMovementComponent = CreateDefaultSubobject<URocketMovementComponent>("RocketMovementComponent");
RocketMovementComponent->bRotationFollowsVelocity = true;
RocketMovementComponent->SetIsReplicated(true);
} }
void AProjectileRocket::Destroyed() void AProjectileRocket::Destroyed()
@ -68,6 +73,10 @@ void AProjectileRocket::DestroyTimerFinished()
void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{ {
if (OtherActor == GetOwner())
{
return;
}
APawn* FiringPawn = GetInstigator(); APawn* FiringPawn = GetInstigator();
if (FiringPawn && HasAuthority()) if (FiringPawn && HasAuthority())
{ {

View File

@ -36,6 +36,10 @@ protected:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
USoundAttenuation* LoopingSoundAttenuation; USoundAttenuation* LoopingSoundAttenuation;
UPROPERTY(VisibleAnywhere)
class URocketMovementComponent* RocketMovementComponent;
private: private:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)

View File

@ -0,0 +1,17 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "RocketMovementComponent.h"
UProjectileMovementComponent::EHandleBlockingHitResult URocketMovementComponent::HandleBlockingHit(const FHitResult& Hit, float TimeTick,
const FVector& MoveDelta, float& SubTickTimeRemaining)
{
Super::HandleBlockingHit(Hit, TimeTick, MoveDelta, SubTickTimeRemaining);
return EHandleBlockingHitResult::AdvanceNextSubstep;
}
void URocketMovementComponent::HandleImpact(const FHitResult& Hit, float TimeSlice, const FVector& MoveDelta)
{
// Rockets should not stop; only explode when their CollisionBox detects a hit
}

View File

@ -0,0 +1,21 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "RocketMovementComponent.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API URocketMovementComponent : public UProjectileMovementComponent
{
GENERATED_BODY()
protected:
virtual EHandleBlockingHitResult HandleBlockingHit(const FHitResult& Hit, float TimeTick, const FVector& MoveDelta, float& SubTickTimeRemaining) override;
virtual void HandleImpact(const FHitResult& Hit, float TimeSlice, const FVector& MoveDelta) override;
};

View File

@ -15,6 +15,7 @@ AWeapon::AWeapon()
{ {
PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bCanEverTick = false;
bReplicates = true; bReplicates = true;
SetReplicateMovement(true);
WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh")); WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));