feat: add logic for jump, sprint and crouch
Added walk speed and sprint speed properties to character Moved dodge properties to character Implement logic for jump, sprint and crouch Changed dodge key from Shift to Alt
This commit is contained in:
parent
c26dcd6eae
commit
89da8c4463
Binary file not shown.
Binary file not shown.
|
|
@ -30,6 +30,9 @@ void AExoPlayerController::BeginPlay()
|
||||||
|
|
||||||
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
||||||
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
|
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
|
||||||
|
|
||||||
|
// Ustawianie w komponencie poruszania prêdkoœci zapisanej w characterze
|
||||||
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerTick(float DeltaTime)
|
void AExoPlayerController::PlayerTick(float DeltaTime)
|
||||||
|
|
@ -48,8 +51,10 @@ void AExoPlayerController::SetupInputComponent()
|
||||||
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
||||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
||||||
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
||||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerCrouch);
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartCrouch);
|
||||||
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSprint);
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopCrouch);
|
||||||
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartSprint);
|
||||||
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopSprint);
|
||||||
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
||||||
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim);
|
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim);
|
||||||
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
||||||
|
|
@ -90,7 +95,7 @@ void AExoPlayerController::Interact()
|
||||||
|
|
||||||
void AExoPlayerController::PlayerJump()
|
void AExoPlayerController::PlayerJump()
|
||||||
{
|
{
|
||||||
|
PlayerCharacter->Jump();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerDodge()
|
void AExoPlayerController::PlayerDodge()
|
||||||
|
|
@ -99,6 +104,8 @@ void AExoPlayerController::PlayerDodge()
|
||||||
|
|
||||||
if (PlayerCharacter->GetCharacterMovement()->IsFalling()) return;
|
if (PlayerCharacter->GetCharacterMovement()->IsFalling()) return;
|
||||||
|
|
||||||
|
if (PlayerCharacter->GetCharacterMovement()->IsCrouching()) return;
|
||||||
|
|
||||||
if (!CanDodge) return;
|
if (!CanDodge) return;
|
||||||
|
|
||||||
CanDodge = false;
|
CanDodge = false;
|
||||||
|
|
@ -109,9 +116,9 @@ void AExoPlayerController::PlayerDodge()
|
||||||
if (DodgeDirection.IsNearlyZero())
|
if (DodgeDirection.IsNearlyZero())
|
||||||
DodgeDirection = PlayerCharacter->GetActorForwardVector();
|
DodgeDirection = PlayerCharacter->GetActorForwardVector();
|
||||||
|
|
||||||
PlayerCharacter->LaunchCharacter(DodgeDirection * DodgeForce, true, true);
|
PlayerCharacter->LaunchCharacter(DodgeDirection * PlayerCharacter->DodgeForce, true, true);
|
||||||
|
|
||||||
GetWorldTimerManager().SetTimer(DodgeCooldownTimer, this, &AExoPlayerController::ResetDodge, DodgeCooldown, false);
|
GetWorldTimerManager().SetTimer(DodgeCooldownTimer, this, &AExoPlayerController::ResetDodge, PlayerCharacter->DodgeCooldown, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::ResetDodge()
|
void AExoPlayerController::ResetDodge()
|
||||||
|
|
@ -119,14 +126,28 @@ void AExoPlayerController::ResetDodge()
|
||||||
CanDodge = true;
|
CanDodge = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerCrouch()
|
void AExoPlayerController::PlayerStartCrouch()
|
||||||
{
|
{
|
||||||
|
PlayerCharacter->Crouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerSprint()
|
void AExoPlayerController::PlayerStopCrouch()
|
||||||
{
|
{
|
||||||
|
PlayerCharacter->UnCrouch();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AExoPlayerController::PlayerStartSprint()
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Start sprint"));
|
||||||
|
|
||||||
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AExoPlayerController::PlayerStopSprint()
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Stop sprint"));
|
||||||
|
|
||||||
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerShoot()
|
void AExoPlayerController::PlayerShoot()
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,18 @@ class EXO_API AExoPlayerCharacter : public AExoCharacterBase
|
||||||
public:
|
public:
|
||||||
AExoPlayerCharacter();
|
AExoPlayerCharacter();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
||||||
|
float DodgeForce = 5000.f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
||||||
|
float DodgeCooldown = 2.f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Movement Properties")
|
||||||
|
float WalkSpeed = 600.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Movement Properties")
|
||||||
|
float SprintSpeed = 1500.0f;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,16 @@ protected:
|
||||||
void ResetDodge();
|
void ResetDodge();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerCrouch(); // LCtrl\C\X
|
void PlayerStartCrouch(); // LCtrl\C\X
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerSprint(); // LShift(Hold)
|
void PlayerStopCrouch(); // LCtrl\C\X
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
|
void PlayerStartSprint(); // LShift(Hold)
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
|
void PlayerStopSprint();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerShoot(); // LPM
|
void PlayerShoot(); // LPM
|
||||||
|
|
@ -97,12 +103,6 @@ protected:
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Dodge Properties")
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Dodge Properties")
|
||||||
FTimerHandle DodgeCooldownTimer;
|
FTimerHandle DodgeCooldownTimer;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
|
||||||
float DodgeForce = 5000.f; // Move to player if future for better modification
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
|
||||||
float DodgeCooldown = 2.f; // Move to player too.
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
|
||||||
bool CanDodge = true;
|
bool CanDodge = true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user