Added FOV when sprinting and finished Sprinting System
This commit is contained in:
		
							parent
							
								
									7f2cc14922
								
							
						
					
					
						commit
						39bd245f57
					
				| @ -71,12 +71,12 @@ void AEndlessVendettaCharacter::BeginPlay() | |||||||
| 	InventoryComponent = Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass())); | 	InventoryComponent = Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass())); | ||||||
| 	WalkSpeed = CharacterMovement->MaxWalkSpeed; | 	WalkSpeed = CharacterMovement->MaxWalkSpeed; | ||||||
| 	OriginalWalkSpeed = CharacterMovement->MaxWalkSpeed; | 	OriginalWalkSpeed = CharacterMovement->MaxWalkSpeed; | ||||||
|  | 	CurrentStamina = MaxStamina; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AEndlessVendettaCharacter::Tick(float DeltaTime) | void AEndlessVendettaCharacter::Tick(float DeltaTime) | ||||||
| { | { | ||||||
| 	Super::Tick(DeltaTime); | 	Super::Tick(DeltaTime); | ||||||
| 
 |  | ||||||
| 	WeaponPickUpSystem(); | 	WeaponPickUpSystem(); | ||||||
| 
 | 
 | ||||||
| 	MoveGroundSpeed = Cast<UMovementComponent>(GetComponentByClass(UMovementComponent::StaticClass()))->Velocity.Size(); | 	MoveGroundSpeed = Cast<UMovementComponent>(GetComponentByClass(UMovementComponent::StaticClass()))->Velocity.Size(); | ||||||
| @ -89,6 +89,27 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) | |||||||
| 	{ | 	{ | ||||||
| 		bIsPlayerMoving = false; | 		bIsPlayerMoving = false; | ||||||
| 	} | 	} | ||||||
|  | 	//PLAYER STAMINA HANDLING
 | ||||||
|  | 	if (bIsPlayerSprinting) | ||||||
|  | 	{ | ||||||
|  | 		CurrentStamina -= FMath::Clamp(StaminaDecreaseRate, 0.0f, 100.0f); | ||||||
|  | 		if (CurrentStamina <= 0.0f) | ||||||
|  | 		{ | ||||||
|  | 			bIsPlayerSprinting = false; | ||||||
|  | 			this->GetFirstPersonCameraComponent()->SetFieldOfView(90); | ||||||
|  | 			CurrentStamina = 0.0f; | ||||||
|  | 			CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	if (!bIsPlayerSprinting) | ||||||
|  | 	{ | ||||||
|  | 		if(CurrentStamina >= 100.0f) | ||||||
|  | 		{ | ||||||
|  | 			CurrentStamina = 100.0f; | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		CurrentStamina += FMath::Clamp(StaminaRegenRate, 0.0f, 100.0f); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AEndlessVendettaCharacter::RegenHealth() | void AEndlessVendettaCharacter::RegenHealth() | ||||||
| @ -521,13 +542,7 @@ void AEndlessVendettaCharacter::Sprint() | |||||||
| 	if (bIsPlayerSprinting) | 	if (bIsPlayerSprinting) | ||||||
| 	{ | 	{ | ||||||
| 		CharacterMovement->MaxWalkSpeed = SprintSpeed; | 		CharacterMovement->MaxWalkSpeed = SprintSpeed; | ||||||
| 		MaxStamina -= StaminaDecreaseRate; | 		this->GetFirstPersonCameraComponent()->SetFieldOfView(100); | ||||||
| 		UE_LOG(LogTemp, Display, TEXT("Walk Speed: %f"), WalkSpeed); |  | ||||||
| 		if (MaxStamina <= 0) |  | ||||||
| 		{ |  | ||||||
| 			CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; |  | ||||||
| 			bIsPlayerSprinting = false; |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -538,7 +553,7 @@ void AEndlessVendettaCharacter::StopSprint() | |||||||
| 	{ | 	{ | ||||||
| 		UE_LOG(LogTemp, Display, TEXT("Player stopped sprinting")); | 		UE_LOG(LogTemp, Display, TEXT("Player stopped sprinting")); | ||||||
| 		CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; | 		CharacterMovement->MaxWalkSpeed = OriginalWalkSpeed; | ||||||
| 		MaxStamina++; | 		this->GetFirstPersonCameraComponent()->SetFieldOfView(90); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -88,11 +88,15 @@ public: | |||||||
| 
 | 
 | ||||||
| 	//STAMINA AND SPRINT SPEED
 | 	//STAMINA AND SPRINT SPEED
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | ||||||
| 	float MaxStamina = 100.0f; | 	float MaxStamina  = 100; | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | ||||||
| 	float StaminaDecreaseRate = 10.0f; | 	float CurrentStamina; | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | ||||||
| 	float SprintSpeed = 1200; | 	float StaminaDecreaseRate = 0.2; | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | ||||||
|  | 	float StaminaRegenRate = 0.05; | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") | ||||||
|  | 	float SprintSpeed = 900; | ||||||
| 
 | 
 | ||||||
| 	//Getting the charMovementComp
 | 	//Getting the charMovementComp
 | ||||||
| 	UCharacterMovementComponent* CharacterMovement = GetCharacterMovement(); | 	UCharacterMovementComponent* CharacterMovement = GetCharacterMovement(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user