Working on netowrked projectiles
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -36,13 +36,13 @@ protected:
|
|||||||
ClassNames ClassName;
|
ClassNames ClassName;
|
||||||
|
|
||||||
/*Functions*/
|
/*Functions*/
|
||||||
UFUNCTION(BlueprintAuthorityOnly, BlueprintCallable, Category = "Health")
|
|
||||||
void TakeDamage(int DamageValue);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*Properties*/
|
/*Properties*/
|
||||||
|
|
||||||
/*Functions*/
|
/*Functions*/
|
||||||
|
UFUNCTION(BlueprintAuthorityOnly, BlueprintCallable, Category = "Health")
|
||||||
|
void TakeDamage(int DamageValue);
|
||||||
|
|
||||||
/*C++ only declarations*/
|
/*C++ only declarations*/
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ struct FHealthSegment : public FTableRowBase
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
||||||
ClassNames Class;
|
ClassNames Class = ClassNames::Basic;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
||||||
TArray<int> SegmentList;
|
TArray<int> SegmentList;
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,10 @@ void ADDICharacter::Tick(float DeltaTime)
|
|||||||
|
|
||||||
void ADDICharacter::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
void ADDICharacter::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||||
{
|
{
|
||||||
if (OtherActor->Owner == this)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AProjectileBase* Projectile = Cast<AProjectileBase>(OtherActor);
|
|
||||||
|
|
||||||
if (HealthComponent && Projectile)
|
}
|
||||||
HealthComponent->TakeDamage(10);
|
|
||||||
|
void ADDICharacter::TakeDamage(int Damage)
|
||||||
|
{
|
||||||
|
HealthComponent->TakeDamage(Damage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void TakeDamage(int Damage);
|
||||||
|
|
||||||
/*C++ only declarations*/
|
/*C++ only declarations*/
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -3,14 +3,22 @@
|
|||||||
|
|
||||||
#include "ProjectileBase.h"
|
#include "ProjectileBase.h"
|
||||||
|
|
||||||
|
#include "OpenConflict/PlayerCharacter/DDICharacter.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
AProjectileBase::AProjectileBase()
|
AProjectileBase::AProjectileBase()
|
||||||
{
|
{
|
||||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// 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;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
bReplicates = true;
|
||||||
|
bNetLoadOnClient = true;
|
||||||
|
|
||||||
|
InitialLifeSpan = 3.f;
|
||||||
|
|
||||||
|
|
||||||
collision = CreateDefaultSubobject<USphereComponent>("Collision");
|
collision = CreateDefaultSubobject<USphereComponent>("Collision");
|
||||||
RootComponent = collision;
|
RootComponent = collision;
|
||||||
|
collision->BodyInstance.SetCollisionProfileName(TEXT("BlockAllDynamic"));
|
||||||
|
|
||||||
projectileMesh = CreateDefaultSubobject<UStaticMeshComponent>("ProjectileMesh");
|
projectileMesh = CreateDefaultSubobject<UStaticMeshComponent>("ProjectileMesh");
|
||||||
projectileMesh->SetupAttachment(collision);
|
projectileMesh->SetupAttachment(collision);
|
||||||
@@ -22,6 +30,9 @@ AProjectileBase::AProjectileBase()
|
|||||||
void AProjectileBase::BeginPlay()
|
void AProjectileBase::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,10 @@ public:
|
|||||||
UProjectileMovementComponent* projectileMotion;
|
UProjectileMovementComponent* projectileMotion;
|
||||||
|
|
||||||
/*Functions*/
|
/*Functions*/
|
||||||
|
UFUNCTION()
|
||||||
|
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||||
|
|
||||||
|
|
||||||
/*C++ only declarations*/
|
/*C++ only declarations*/
|
||||||
private:
|
private:
|
||||||
/*Properties*/
|
/*Properties*/
|
||||||
|
|||||||
27
Source/OpenConflict/Weapons/WeaponBase.cpp
Normal file
27
Source/OpenConflict/Weapons/WeaponBase.cpp
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
26
Source/OpenConflict/Weapons/WeaponBase.h
Normal file
26
Source/OpenConflict/Weapons/WeaponBase.h
Normal 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;
|
||||||
|
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user