diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 69e1aae..6b2bec4 100644 Binary files a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset and b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset differ diff --git a/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset b/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset index a1cc191..9046115 100644 Binary files a/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset and b/Content/Blueprints/Weapon/Projectiles/BP_Rocket.uasset differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index f0f2f26..05c4f8f 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -267,6 +267,9 @@ void ABlasterCharacter::PlayReloadMontage() case EWeaponType::EWT_AssaultRifle: SectionName = FName("Rifle"); break; + case EWeaponType::EWT_RocketLauncher: + SectionName = FName("Rifle"); // Todo: create rocket reload montage section + break; } AnimInstance->Montage_JumpToSection(SectionName); diff --git a/Source/Blaster/Weapon/Projectile.cpp b/Source/Blaster/Weapon/Projectile.cpp index ed3ecfe..1c1dee7 100644 --- a/Source/Blaster/Weapon/Projectile.cpp +++ b/Source/Blaster/Weapon/Projectile.cpp @@ -4,9 +4,7 @@ #include "Projectile.h" #include "Blaster/Blaster.h" -#include "Blaster/Character/BlasterCharacter.h" #include "Components/BoxComponent.h" -#include "GameFramework/ProjectileMovementComponent.h" #include "Kismet/GameplayStatics.h" #include "Sound/SoundCue.h" @@ -23,9 +21,6 @@ AProjectile::AProjectile() CollisionBox->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); CollisionBox->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block); CollisionBox->SetCollisionResponseToChannel(ECC_SkeletalMesh, ECR_Block); - - ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); - ProjectileMovementComponent->bRotationFollowsVelocity = true; } void AProjectile::BeginPlay() diff --git a/Source/Blaster/Weapon/Projectile.h b/Source/Blaster/Weapon/Projectile.h index 3bdc169..c3f0cd3 100644 --- a/Source/Blaster/Weapon/Projectile.h +++ b/Source/Blaster/Weapon/Projectile.h @@ -35,11 +35,11 @@ protected: UPROPERTY(EditAnywhere) class UBoxComponent* CollisionBox; -private: - UPROPERTY(VisibleAnywhere) class UProjectileMovementComponent* ProjectileMovementComponent; - + +private: + UPROPERTY(EditAnywhere) class UParticleSystem* Tracer; diff --git a/Source/Blaster/Weapon/ProjectileBullet.cpp b/Source/Blaster/Weapon/ProjectileBullet.cpp index 0cb814d..74231c7 100644 --- a/Source/Blaster/Weapon/ProjectileBullet.cpp +++ b/Source/Blaster/Weapon/ProjectileBullet.cpp @@ -4,8 +4,16 @@ #include "ProjectileBullet.h" #include "GameFramework/Character.h" +#include "GameFramework/ProjectileMovementComponent.h" #include "Kismet/GameplayStatics.h" +AProjectileBullet::AProjectileBullet() +{ + ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); + ProjectileMovementComponent->bRotationFollowsVelocity = true; + ProjectileMovementComponent->SetIsReplicated(true); +} + void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { ACharacter* OwnerCharacter = Cast(GetOwner()); diff --git a/Source/Blaster/Weapon/ProjectileBullet.h b/Source/Blaster/Weapon/ProjectileBullet.h index 8e3e8d7..1631542 100644 --- a/Source/Blaster/Weapon/ProjectileBullet.h +++ b/Source/Blaster/Weapon/ProjectileBullet.h @@ -14,6 +14,10 @@ class BLASTER_API AProjectileBullet : public AProjectile { GENERATED_BODY() +public: + + AProjectileBullet(); + protected: virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override; diff --git a/Source/Blaster/Weapon/ProjectileRocket.cpp b/Source/Blaster/Weapon/ProjectileRocket.cpp index 45c61e1..529fec1 100644 --- a/Source/Blaster/Weapon/ProjectileRocket.cpp +++ b/Source/Blaster/Weapon/ProjectileRocket.cpp @@ -6,6 +6,7 @@ #include "Kismet/GameplayStatics.h" #include "NiagaraFunctionLibrary.h" #include "NiagaraComponent.h" +#include "RocketMovementComponent.h" #include "Components/AudioComponent.h" #include "Components/BoxComponent.h" #include "Sound/SoundCue.h" @@ -15,6 +16,10 @@ AProjectileRocket::AProjectileRocket() RocketMesh = CreateDefaultSubobject(TEXT("Rocket Mesh")); RocketMesh->SetupAttachment(RootComponent); RocketMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); + + RocketMovementComponent = CreateDefaultSubobject("RocketMovementComponent"); + RocketMovementComponent->bRotationFollowsVelocity = true; + RocketMovementComponent->SetIsReplicated(true); } void AProjectileRocket::Destroyed() @@ -68,6 +73,10 @@ void AProjectileRocket::DestroyTimerFinished() void AProjectileRocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { + if (OtherActor == GetOwner()) + { + return; + } APawn* FiringPawn = GetInstigator(); if (FiringPawn && HasAuthority()) { diff --git a/Source/Blaster/Weapon/ProjectileRocket.h b/Source/Blaster/Weapon/ProjectileRocket.h index 122d015..94af218 100644 --- a/Source/Blaster/Weapon/ProjectileRocket.h +++ b/Source/Blaster/Weapon/ProjectileRocket.h @@ -36,6 +36,10 @@ protected: UPROPERTY(EditAnywhere) USoundAttenuation* LoopingSoundAttenuation; + + UPROPERTY(VisibleAnywhere) + class URocketMovementComponent* RocketMovementComponent; + private: UPROPERTY(VisibleAnywhere) diff --git a/Source/Blaster/Weapon/RocketMovementComponent.cpp b/Source/Blaster/Weapon/RocketMovementComponent.cpp new file mode 100644 index 0000000..a75878f --- /dev/null +++ b/Source/Blaster/Weapon/RocketMovementComponent.cpp @@ -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 +} diff --git a/Source/Blaster/Weapon/RocketMovementComponent.h b/Source/Blaster/Weapon/RocketMovementComponent.h new file mode 100644 index 0000000..ccf1438 --- /dev/null +++ b/Source/Blaster/Weapon/RocketMovementComponent.h @@ -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; +}; diff --git a/Source/Blaster/Weapon/Weapon.cpp b/Source/Blaster/Weapon/Weapon.cpp index 3550513..98cec9a 100644 --- a/Source/Blaster/Weapon/Weapon.cpp +++ b/Source/Blaster/Weapon/Weapon.cpp @@ -15,6 +15,7 @@ AWeapon::AWeapon() { PrimaryActorTick.bCanEverTick = false; bReplicates = true; + SetReplicateMovement(true); WeaponMesh = CreateDefaultSubobject(TEXT("WeaponMesh"));