Working on netowrked projectiles

This commit is contained in:
2025-12-08 21:35:24 -05:00
parent a3a120491d
commit dd3648f5b9
10 changed files with 86 additions and 9 deletions

View File

@@ -3,14 +3,22 @@
#include "ProjectileBase.h"
#include "OpenConflict/PlayerCharacter/DDICharacter.h"
// Sets default values
AProjectileBase::AProjectileBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
bNetLoadOnClient = true;
InitialLifeSpan = 3.f;
collision = CreateDefaultSubobject<USphereComponent>("Collision");
RootComponent = collision;
collision->BodyInstance.SetCollisionProfileName(TEXT("BlockAllDynamic"));
projectileMesh = CreateDefaultSubobject<UStaticMeshComponent>("ProjectileMesh");
projectileMesh->SetupAttachment(collision);
@@ -22,6 +30,9 @@ AProjectileBase::AProjectileBase()
void AProjectileBase::BeginPlay()
{
Super::BeginPlay();
if (collision)
collision->OnComponentHit.AddDynamic(this, &AProjectileBase::OnHit);
}
@@ -32,3 +43,12 @@ void AProjectileBase::Tick(float DeltaTime)
}
void AProjectileBase::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
if (ADDICharacter* character = Cast<ADDICharacter>(OtherActor))
{
Destroy();
character->TakeDamage(10);
}
}

View File

@@ -33,7 +33,10 @@ public:
UProjectileMovementComponent* projectileMotion;
/*Functions*/
UFUNCTION()
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
/*C++ only declarations*/
private:
/*Properties*/

View File

@@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "WeaponBase.h"
// Sets default values
AWeaponBase::AWeaponBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AWeaponBase::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AWeaponBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "WeaponBase.generated.h"
UCLASS()
class OPENCONFLICT_API AWeaponBase : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AWeaponBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};