Updated TempCharacter for Jump and Sneak

Added A sneak function and Jump function for the character
This commit is contained in:
MARCEL HARA 2023-02-06 15:26:22 +00:00
parent 0cf4ace43a
commit 5b4da1f02e
4 changed files with 40 additions and 16 deletions

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,8 @@
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h" #include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "the_twilight_abyss/MerchantInteraction/Interaction.h" #include "the_twilight_abyss/MerchantInteraction/Interaction.h"
@ -17,6 +19,7 @@ ATempCharacter::ATempCharacter()
Inventory->MaxItemSlots = 10; Inventory->MaxItemSlots = 10;
GoldBalance = GoldBalance; GoldBalance = GoldBalance;
Health = Health; Health = Health;
this->GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -25,6 +28,7 @@ void ATempCharacter::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
Health = 100; Health = 100;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>()); ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
PlayerCapsule = GetCapsuleComponent();
} }
//Binds the input we made in the setup player component to the forward vector //Binds the input we made in the setup player component to the forward vector
@ -40,6 +44,15 @@ void ATempCharacter::RightMoveInput(float Axis)
void ATempCharacter::Sneak() void ATempCharacter::Sneak()
{ {
UE_LOG(LogTemp, Display, TEXT("Sneak activated"));
if (bIsCrouched)
{
UnCrouch();
}
else
{
Crouch();
}
} }
@ -60,6 +73,7 @@ void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo
PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput); PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput);
PlayerInputComponent->BindAction(TEXT("Jump"), IE_Pressed, this, &ATempCharacter::Jump); PlayerInputComponent->BindAction(TEXT("Jump"), IE_Pressed, this, &ATempCharacter::Jump);
PlayerInputComponent->BindAction(TEXT("Sneak"), IE_Pressed, this, &ATempCharacter::Sneak); PlayerInputComponent->BindAction(TEXT("Sneak"), IE_Pressed, this, &ATempCharacter::Sneak);
PlayerInputComponent->BindAction(TEXT("Sneak"), IE_Released, this, &ATempCharacter::Sneak);
PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
} }
@ -149,14 +163,17 @@ void ATempCharacter::LineTraceLogic()
void ATempCharacter::InputDisabler() void ATempCharacter::InputDisabler()
{ {
UE_LOG(LogTemp, Display, TEXT("Disabling playermovement")); //Disable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->DisableInput(GetWorld()->GetFirstPlayerController());
}
//Set to UI Mode Only
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeUIOnly());
PlayerController->bShowMouseCursor = true;
disableTab = true; disableTab = true;
//GetWorld()->GetFirstPlayerController()->InputComponent->RemoveActionBinding("Interact", IE_Pressed);
GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(true);
GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(true);
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
GetWorld()->GetFirstPlayerController()->bEnableClickEvents = true;
GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = true;
if (ThisCamera == nullptr) if (ThisCamera == nullptr)
{ {
return; return;
@ -173,14 +190,18 @@ void ATempCharacter::InputDisabler()
void ATempCharacter::InputEnabler() void ATempCharacter::InputEnabler()
{ {
//Enable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
}
//Reset UI Mode
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeGameOnly());
PlayerController->bShowMouseCursor = false;
UE_LOG(LogTemp, Display, TEXT("Enabling Inputs")); UE_LOG(LogTemp, Display, TEXT("Enabling Inputs"));
disableTab = true; disableTab = true;
GetWorld()->GetFirstPlayerController()->SetIgnoreLookInput(false);
GetWorld()->GetFirstPlayerController()->SetIgnoreMoveInput(false);
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false;
GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false;
GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false;
//GetWorld()->GetFirstPlayerController()->InputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
TraceDistance = 300; TraceDistance = 300;
if (ThisCamera == nullptr) if (ThisCamera == nullptr)
{ {

View File

@ -28,6 +28,9 @@ protected:
UFUNCTION() UFUNCTION()
void Sneak(); void Sneak();
UCapsuleComponent* PlayerCapsule;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;