Add functionality to change movement speed depending on status
This commit is contained in:
parent
9e7417eb59
commit
3d4ef7e3c0
|
@ -242,12 +242,16 @@ void APlayerCharacter::QuitCallback(const FInputActionInstance& Instance)
|
||||||
|
|
||||||
void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * SprintSpeedMultiplier;
|
IsSpriting = true;
|
||||||
|
|
||||||
|
SetMovementSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed;
|
IsSpriting = false;
|
||||||
|
|
||||||
|
SetMovementSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
|
void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
|
||||||
|
@ -375,6 +379,22 @@ void APlayerCharacter::OnDeath()
|
||||||
ClearAllTimers();
|
ClearAllTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::SetMovementSpeed()
|
||||||
|
{
|
||||||
|
if (IsADS)
|
||||||
|
{
|
||||||
|
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * ADSSpeedMultiplier;
|
||||||
|
}
|
||||||
|
else if (IsSpriting)
|
||||||
|
{
|
||||||
|
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * SprintSpeedMultiplier;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
float value = Instance.GetValue().Get<float>();
|
float value = Instance.GetValue().Get<float>();
|
||||||
|
@ -391,6 +411,10 @@ void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Insta
|
||||||
|
|
||||||
void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
|
IsADS = true;
|
||||||
|
|
||||||
|
SetMovementSpeed();
|
||||||
|
|
||||||
FLatentActionInfo LatentActionInfo;
|
FLatentActionInfo LatentActionInfo;
|
||||||
LatentActionInfo.CallbackTarget = this;
|
LatentActionInfo.CallbackTarget = this;
|
||||||
CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
|
CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
|
||||||
|
@ -403,6 +427,10 @@ void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& In
|
||||||
|
|
||||||
void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
|
IsADS = false;
|
||||||
|
|
||||||
|
SetMovementSpeed();
|
||||||
|
|
||||||
FLatentActionInfo LatentActionInfo;
|
FLatentActionInfo LatentActionInfo;
|
||||||
LatentActionInfo.CallbackTarget = this;
|
LatentActionInfo.CallbackTarget = this;
|
||||||
CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
|
CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
|
||||||
|
|
|
@ -65,6 +65,9 @@ protected:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
float SprintSpeedMultiplier = 2.0f;
|
float SprintSpeedMultiplier = 2.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
float ADSSpeedMultiplier = 0.5f;
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
float CameraBlendTime = 0.1f;
|
float CameraBlendTime = 0.1f;
|
||||||
|
|
||||||
|
@ -91,6 +94,10 @@ private:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||||
UAIPerceptionStimuliSourceComponent* PerceptionSource;
|
UAIPerceptionStimuliSourceComponent* PerceptionSource;
|
||||||
|
|
||||||
|
bool IsSpriting = false;
|
||||||
|
|
||||||
|
bool IsADS = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
APlayerCharacter();
|
APlayerCharacter();
|
||||||
|
@ -159,4 +166,6 @@ protected:
|
||||||
virtual void OnDamaged() override;
|
virtual void OnDamaged() override;
|
||||||
|
|
||||||
virtual void OnDeath() override;
|
virtual void OnDeath() override;
|
||||||
|
|
||||||
|
void SetMovementSpeed();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue