Compare commits
4 Commits
48bb8f9ef6
...
ab3f624ade
Author | SHA1 | Date |
---|---|---|
baz | ab3f624ade | |
baz | af8d8364a4 | |
baz | 01aeecf953 | |
baz | 56aa855a7c |
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
||||||
|
|
||||||
AEnemyCharacter::AEnemyCharacter()
|
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) : ANakatomiCharacter(ObjectInitializer)
|
||||||
{
|
{
|
||||||
RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters"));
|
RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters"));
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ private:
|
||||||
FTimerHandle CooldownTimerHandle;
|
FTimerHandle CooldownTimerHandle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AEnemyCharacter();
|
AEnemyCharacter(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
UBehaviorTree* GetBehaviourTree();
|
UBehaviorTree* GetBehaviourTree();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "NakatomiCMC.h"
|
||||||
|
|
||||||
|
#include <GameFramework/Character.h>
|
||||||
|
|
||||||
|
// Checks if we can combine the NewMove with the current move to save on data.
|
||||||
|
// If all the data in a saved move is identical, if true, we cam tell the server to run the existing move instead.
|
||||||
|
bool UNakatomiCMC::FSavedMove_Nakatomi::CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter,
|
||||||
|
float MaxDelta) const
|
||||||
|
{
|
||||||
|
FSavedMove_Nakatomi* newMove = static_cast<FSavedMove_Nakatomi*>(NewMove.Get());
|
||||||
|
|
||||||
|
// Check if values can be combined, if not return false, if true allow super to handle combining data
|
||||||
|
if (Saved_bWantsToSprint != newMove->Saved_bWantsToSprint)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FSavedMove_Character::CanCombineWith(NewMove, InCharacter, MaxDelta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset a save move object to empty
|
||||||
|
void UNakatomiCMC::FSavedMove_Nakatomi::Clear()
|
||||||
|
{
|
||||||
|
FSavedMove_Character::Clear();
|
||||||
|
|
||||||
|
Saved_bWantsToSprint = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 UNakatomiCMC::FSavedMove_Nakatomi::GetCompressedFlags() const
|
||||||
|
{
|
||||||
|
uint8 Result = Super::GetCompressedFlags();
|
||||||
|
|
||||||
|
if (Saved_bWantsToSprint) Result = ~FLAG_Custom_0;
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::FSavedMove_Nakatomi::SetMoveFor(ACharacter* C, float InDeltaTime, FVector const& NewAccel,
|
||||||
|
FNetworkPredictionData_Client_Character& ClientData)
|
||||||
|
{
|
||||||
|
FSavedMove_Character::SetMoveFor(C, InDeltaTime, NewAccel, ClientData);
|
||||||
|
|
||||||
|
UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement());
|
||||||
|
|
||||||
|
Saved_bWantsToSprint = CharacterMovement->Safe_bWantsToSprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C)
|
||||||
|
{
|
||||||
|
FSavedMove_Character::PrepMoveFor(C);
|
||||||
|
|
||||||
|
UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement());
|
||||||
|
|
||||||
|
CharacterMovement->Safe_bWantsToSprint = Saved_bWantsToSprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNakatomiCMC::FNetworkPredictionData_Client_Nakatomi::FNetworkPredictionData_Client_Nakatomi(
|
||||||
|
const UCharacterMovementComponent& ClientMovement) : Super(ClientMovement)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FSavedMovePtr UNakatomiCMC::FNetworkPredictionData_Client_Nakatomi::AllocateNewMove()
|
||||||
|
{
|
||||||
|
return FSavedMovePtr(new FSavedMove_Nakatomi());
|
||||||
|
}
|
||||||
|
|
||||||
|
FNetworkPredictionData_Client* UNakatomiCMC::GetPredictionData_Client() const
|
||||||
|
{
|
||||||
|
check(PawnOwner != nullptr)
|
||||||
|
|
||||||
|
if (ClientPredictionData == nullptr)
|
||||||
|
{
|
||||||
|
UNakatomiCMC* MutableThis = const_cast<UNakatomiCMC*>(this);
|
||||||
|
|
||||||
|
MutableThis->ClientPredictionData = new FNetworkPredictionData_Client_Nakatomi(*this);
|
||||||
|
MutableThis->ClientPredictionData->MaxSmoothNetUpdateDist = 92.f;
|
||||||
|
MutableThis->ClientPredictionData->NoSmoothNetUpdateDist = 140.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ClientPredictionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNakatomiCMC::UNakatomiCMC(): Safe_bWantsToSprint(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::UpdateFromCompressedFlags(uint8 Flags)
|
||||||
|
{
|
||||||
|
Super::UpdateFromCompressedFlags(Flags);
|
||||||
|
|
||||||
|
Safe_bWantsToSprint = (Flags & FSavedMove_Character::FLAG_Custom_0) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::OnMovementUpdated(float DeltaSeconds, const FVector& OldLocation, const FVector& OldVelocity)
|
||||||
|
{
|
||||||
|
Super::OnMovementUpdated(DeltaSeconds, OldLocation, OldVelocity);
|
||||||
|
|
||||||
|
if (MovementMode == MOVE_Walking)
|
||||||
|
{
|
||||||
|
if (Safe_bWantsToSprint)
|
||||||
|
{
|
||||||
|
MaxWalkSpeed = Sprint_MaxWalkSpeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MaxWalkSpeed = Walk_MaxWalkSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::EnableSprint()
|
||||||
|
{
|
||||||
|
Safe_bWantsToSprint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiCMC::DisableSprint()
|
||||||
|
{
|
||||||
|
Safe_bWantsToSprint = false;
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
|
#include "NakatomiCMC.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
class FSavedMove_Nakatomi : public FSavedMove_Character
|
||||||
|
{
|
||||||
|
typedef FSavedMove_Character Super;
|
||||||
|
|
||||||
|
uint8 Saved_bWantsToSprint:1;
|
||||||
|
|
||||||
|
virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override;
|
||||||
|
virtual void Clear() override;
|
||||||
|
virtual uint8 GetCompressedFlags() const override;
|
||||||
|
virtual void SetMoveFor(ACharacter* C, float InDeltaTime, FVector const& NewAccel, FNetworkPredictionData_Client_Character& ClientData) override;
|
||||||
|
virtual void PrepMoveFor(ACharacter* C) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FNetworkPredictionData_Client_Nakatomi : public FNetworkPredictionData_Client_Character
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FNetworkPredictionData_Client_Nakatomi(const UCharacterMovementComponent& ClientMovement);
|
||||||
|
|
||||||
|
typedef FNetworkPredictionData_Client_Character Super;
|
||||||
|
|
||||||
|
virtual FSavedMovePtr AllocateNewMove() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly) float Sprint_MaxWalkSpeed;
|
||||||
|
UPROPERTY(EditDefaultsOnly) float Walk_MaxWalkSpeed;
|
||||||
|
|
||||||
|
bool Safe_bWantsToSprint;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UNakatomiCMC();
|
||||||
|
|
||||||
|
FNetworkPredictionData_Client* GetPredictionData_Client() const override;
|
||||||
|
protected:
|
||||||
|
virtual void UpdateFromCompressedFlags(uint8 Flags) override;
|
||||||
|
|
||||||
|
virtual void OnMovementUpdated(float DeltaSeconds, const FVector& OldLocation, const FVector& OldVelocity) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void EnableSprint();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void DisableSprint();
|
||||||
|
};
|
|
@ -3,12 +3,17 @@
|
||||||
|
|
||||||
#include "NakatomiCharacter.h"
|
#include "NakatomiCharacter.h"
|
||||||
|
|
||||||
|
#include "NakatomiCMC.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
ANakatomiCharacter::ANakatomiCharacter()
|
ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super(
|
||||||
|
ObjectInitializer.SetDefaultSubobjectClass<UNakatomiCMC>(ACharacter::CharacterMovementComponentName))
|
||||||
{
|
{
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// Set this character 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;
|
||||||
|
|
||||||
|
NakatomiCMC = Cast<UNakatomiCMC>(GetCharacterMovement());
|
||||||
|
|
||||||
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||||
HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged");
|
HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||||
HealthComponent->OnDeath.BindUFunction(this, "OnDeath");
|
HealthComponent->OnDeath.BindUFunction(this, "OnDeath");
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
#include "NakatomiCMC.h"
|
||||||
#include "Throwable.h"
|
#include "Throwable.h"
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
#include "NakatomiCharacter.generated.h"
|
#include "NakatomiCharacter.generated.h"
|
||||||
|
@ -38,6 +39,10 @@ public:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TArray<TSubclassOf<AThrowable>> ThrowableInventory;
|
TArray<TSubclassOf<AThrowable>> ThrowableInventory;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
|
UNakatomiCMC* NakatomiCMC;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleDefaultsOnly)
|
UPROPERTY(VisibleDefaultsOnly)
|
||||||
UHealthComponent* HealthComponent = nullptr;
|
UHealthComponent* HealthComponent = nullptr;
|
||||||
|
@ -47,9 +52,10 @@ private:
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int MaximumThrowableInventorySize = 4;
|
int MaximumThrowableInventorySize = 4;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
ANakatomiCharacter();
|
ANakatomiCharacter(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
APlayerCharacter::APlayerCharacter()
|
APlayerCharacter::APlayerCharacter(const FObjectInitializer& ObjectInitializer) : ANakatomiCharacter(ObjectInitializer)
|
||||||
{
|
{
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// Set this character 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;
|
||||||
PrimaryActorTick.SetTickFunctionEnable(true);
|
PrimaryActorTick.SetTickFunctionEnable(true);
|
||||||
PrimaryActorTick.bStartWithTickEnabled = true;
|
PrimaryActorTick.bStartWithTickEnabled = true;
|
||||||
|
|
||||||
//bUseControllerRotationPitch = true;
|
//bUseControllerRotationPitch = true;
|
||||||
//bUseControllerRotationYaw = true;
|
//bUseControllerRotationYaw = true;
|
||||||
//bUseControllerRotationRoll = false;
|
//bUseControllerRotationRoll = false;
|
||||||
|
@ -56,9 +56,8 @@ APlayerCharacter::APlayerCharacter()
|
||||||
CameraADSSpringArmComponent->SocketOffset = {0.0f, 50.0f, 75.0f};
|
CameraADSSpringArmComponent->SocketOffset = {0.0f, 50.0f, 75.0f};
|
||||||
|
|
||||||
// Setup the character movement
|
// Setup the character movement
|
||||||
UCharacterMovementComponent* CharacterMovementComponent = GetCharacterMovement();
|
GetCharacterMovement()->AirControl = 1.0f;
|
||||||
CharacterMovementComponent->AirControl = 1.0f;
|
GetCharacterMovement()->bOrientRotationToMovement = true;
|
||||||
CharacterMovementComponent->bOrientRotationToMovement = true;
|
|
||||||
|
|
||||||
// Setup the character perception component
|
// Setup the character perception component
|
||||||
PerceptionSource = CreateDefaultSubobject<UAIPerceptionStimuliSourceComponent>(TEXT("Perception Source Stimuli"));
|
PerceptionSource = CreateDefaultSubobject<UAIPerceptionStimuliSourceComponent>(TEXT("Perception Source Stimuli"));
|
||||||
|
@ -269,16 +268,18 @@ void APlayerCharacter::QuitCallback(const FInputActionInstance& Instance)
|
||||||
|
|
||||||
void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
IsSpriting = true;
|
if (NakatomiCMC)
|
||||||
|
{
|
||||||
SetMovementSpeed();
|
NakatomiCMC->EnableSprint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
IsSpriting = false;
|
if (NakatomiCMC)
|
||||||
|
{
|
||||||
SetMovementSpeed();
|
NakatomiCMC->DisableSprint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
|
void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
|
||||||
|
@ -450,7 +451,7 @@ void APlayerCharacter::OnDeath()
|
||||||
|
|
||||||
void APlayerCharacter::SetMovementSpeed()
|
void APlayerCharacter::SetMovementSpeed()
|
||||||
{
|
{
|
||||||
if (IsADS)
|
/*if (IsADS)
|
||||||
{
|
{
|
||||||
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * ADSSpeedMultiplier;
|
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * ADSSpeedMultiplier;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +462,7 @@ void APlayerCharacter::SetMovementSpeed()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed;
|
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
||||||
#include "InteractableComponent.h"
|
#include "InteractableComponent.h"
|
||||||
|
#include "NakatomiCMC.h"
|
||||||
#include "Throwable.h"
|
#include "Throwable.h"
|
||||||
#include "PlayerCharacter.generated.h"
|
#include "PlayerCharacter.generated.h"
|
||||||
|
|
||||||
|
@ -95,6 +96,9 @@ protected:
|
||||||
float DefaultAimSensitivity = 45.0f;
|
float DefaultAimSensitivity = 45.0f;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
|
// UNakatomiCMC* NakatomiCMC;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||||
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
||||||
|
|
||||||
|
@ -132,7 +136,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
APlayerCharacter();
|
APlayerCharacter(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
|
|
Loading…
Reference in New Issue