Create Set Movement Speed Task
This commit is contained in:
		
							parent
							
								
									beb18734b1
								
							
						
					
					
						commit
						2f9cc901e2
					
				
							
								
								
									
										
											BIN
										
									
								
								Content/Enemy/Worker/PatrolMovementSpeed.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Enemy/Worker/PatrolMovementSpeed.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								Source/Nakatomi/EPatrolMovementEnum.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Source/Nakatomi/EPatrolMovementEnum.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings.
 | ||||
| 
 | ||||
| 
 | ||||
| #include "EPatrolMovementEnum.h" | ||||
							
								
								
									
										15
									
								
								Source/Nakatomi/EPatrolMovementEnum.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Source/Nakatomi/EPatrolMovementEnum.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings.
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| 
 | ||||
| /**
 | ||||
|  *  | ||||
|  */ | ||||
| UENUM(BlueprintType) | ||||
| enum class EPatrolMovementEnum : uint8 | ||||
| { | ||||
| 	SLOWWALK UMETA(DisplayName = "Slow Walk"), | ||||
| 	WALK UMETA(DisplayName = "Walk"), | ||||
| }; | ||||
| @ -19,6 +19,12 @@ void UNakatomiCMC::InitializeComponent() | ||||
| 	NakatomiCharacterOwner = Cast<ANakatomiCharacter>(GetOwner()); | ||||
| } | ||||
| 
 | ||||
| void UNakatomiCMC::BeginPlay() | ||||
| { | ||||
| 	Super::BeginPlay(); | ||||
| 	DefaultMaxWalkSpeed = Walk_MaxWalkSpeed; | ||||
| } | ||||
| 
 | ||||
| // 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, | ||||
| @ -271,6 +277,16 @@ bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode | ||||
| 	return MovementMode == MOVE_Custom && CustomMovementMode == InCustomMovementMode; | ||||
| } | ||||
| 
 | ||||
| void UNakatomiCMC::SetMaxWalkSpeed(float newMaxSpeed) | ||||
| { | ||||
| 	Walk_MaxWalkSpeed = newMaxSpeed; | ||||
| } | ||||
| 
 | ||||
| void UNakatomiCMC::SetMaxWalkSpeedToDefault() | ||||
| { | ||||
| 	Walk_MaxWalkSpeed = DefaultMaxWalkSpeed; | ||||
| } | ||||
| 
 | ||||
| void UNakatomiCMC::EnterSlide() | ||||
| { | ||||
| 	Safe_bWantsToSlide = true; | ||||
|  | ||||
| @ -108,6 +108,8 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent | ||||
| 	UPROPERTY(Transient) | ||||
| 	ANakatomiCharacter* NakatomiCharacterOwner; | ||||
| 
 | ||||
| 	float DefaultMaxWalkSpeed; | ||||
| 
 | ||||
| public: | ||||
| 	UPROPERTY(BlueprintAssignable) | ||||
| 	FDashStartDelegate DashStartDelegate; | ||||
| @ -118,6 +120,8 @@ public: | ||||
| protected: | ||||
| 	virtual void InitializeComponent() override; | ||||
| 
 | ||||
| 	virtual void BeginPlay() override; | ||||
| 
 | ||||
| 	virtual FNetworkPredictionData_Client* GetPredictionData_Client() const override; | ||||
| 
 | ||||
| protected: | ||||
| @ -167,6 +171,12 @@ public: | ||||
| 	UFUNCTION() | ||||
| 	bool IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const; | ||||
| 
 | ||||
| 	UFUNCTION() | ||||
| 	void SetMaxWalkSpeed(float newMaxSpeed); | ||||
| 
 | ||||
| 	UFUNCTION() | ||||
| 	void SetMaxWalkSpeedToDefault(); | ||||
| 
 | ||||
| private: | ||||
| 	void EnterSlide(); | ||||
| 	void ExitSlide(); | ||||
|  | ||||
							
								
								
									
										30
									
								
								Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Source/Nakatomi/Tasks/BTTSetMovementSpeed.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings.
 | ||||
| 
 | ||||
| 
 | ||||
| #include "../Tasks/BTTSetMovementSpeed.h" | ||||
| 
 | ||||
| #include "Nakatomi/EnemyAIController.h" | ||||
| #include "Nakatomi/NakatomiCMC.h" | ||||
| 
 | ||||
| enum class EPatrolMovementEnum : uint8; | ||||
| 
 | ||||
| EBTNodeResult::Type UBTTSetMovementSpeed::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) | ||||
| { | ||||
| 	AEnemyAIController* enemyController = Cast<AEnemyAIController>(owner.GetAIOwner()); | ||||
| 	AEnemyCharacter* enemyPawn = Cast<AEnemyCharacter>(enemyController->GetPawn()); | ||||
| 
 | ||||
| 	switch (MaxWalkSpeedKey) | ||||
| 	{ | ||||
| 	case EPatrolMovementEnum::SLOWWALK: | ||||
| 		enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(slowWalkSpeed); | ||||
| 		break; | ||||
| 	case EPatrolMovementEnum::WALK: | ||||
| 		enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeed(walkSpeed); | ||||
| 		break; | ||||
| 	default: | ||||
| 		enemyPawn->GetCharacterMovementComponent()->SetMaxWalkSpeedToDefault(); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| 	return EBTNodeResult::Succeeded; | ||||
| } | ||||
							
								
								
									
										32
									
								
								Source/Nakatomi/Tasks/BTTSetMovementSpeed.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Source/Nakatomi/Tasks/BTTSetMovementSpeed.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| // Fill out your copyright notice in the Description page of Project Settings.
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| #include "BehaviorTree/BTTaskNode.h" | ||||
| #include "Nakatomi/EPatrolMovementEnum.h" | ||||
| #include "BTTSetMovementSpeed.generated.h" | ||||
| 
 | ||||
| /**
 | ||||
|  *  | ||||
|  */ | ||||
| UCLASS() | ||||
| class NAKATOMI_API UBTTSetMovementSpeed : public UBTTaskNode | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| 
 | ||||
| public: | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, Category = "Options", | ||||
| 		Meta = (AllowPrivateAccess = "true", DisplayName = "Max Walk Speed Key")) | ||||
| 	EPatrolMovementEnum MaxWalkSpeedKey; | ||||
| 
 | ||||
| private: | ||||
| 	float slowWalkSpeed = 250.0f; | ||||
| 	 | ||||
| 	float walkSpeed = 500.0f; | ||||
| 	 | ||||
| public: | ||||
| 	virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; | ||||
| 	 | ||||
| }; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user