Merge pull request #7 from Games-Academy-Student-Work-22-23/additional-movement

Additional movement
This commit is contained in:
Philip W 2023-02-06 15:57:36 +00:00 committed by GitHub Enterprise
commit 73262b425e
6 changed files with 68 additions and 23 deletions

View File

@ -82,6 +82,7 @@ DoubleClickTime=0.200000
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar)
+ActionMappings=(ActionName="Interact",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E)
+ActionMappings=(ActionName="RightClick",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton)
+ActionMappings=(ActionName="Sneak",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftControl)
+AxisMappings=(AxisName="Look Up / Down Gamepad",Scale=1.000000,Key=Gamepad_RightY)
+AxisMappings=(AxisName="Look Up / Down Mouse",Scale=-1.000000,Key=MouseY)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY)

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/Top_layer_level.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -5,7 +5,10 @@
#include "Blueprint/UserWidget.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.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 <Runtime/Engine/Classes/Kismet/GameplayStatics.h>
// CONSTRUCTOR
@ -17,6 +20,8 @@ ATempCharacter::ATempCharacter()
Inventory->MaxItemSlots = 10;
GoldBalance = GoldBalance;
Health = Health;
this->GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
}
// Called when the game starts or when spawned
@ -25,6 +30,11 @@ void ATempCharacter::BeginPlay()
Super::BeginPlay();
Health = 100;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
PlayerCapsule = GetCapsuleComponent();
TArray<AActor*> AllActorsInScene;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), APostProcessVolume::StaticClass(), AllActorsInScene);
PostProcessVolume = Cast<APostProcessVolume>(AllActorsInScene[0]);
}
//Binds the input we made in the setup player component to the forward vector
@ -38,6 +48,22 @@ void ATempCharacter::RightMoveInput(float Axis)
AddMovementInput(UKismetMathLibrary::GetRightVector(FRotator(0, GetControlRotation().Yaw, 0)) * Axis);
}
void ATempCharacter::Sneak()
{
UE_LOG(LogTemp, Display, TEXT("Sneak activated"));
if (bIsCrouched)
{
UnCrouch();
PostProcessVolume->Settings.VignetteIntensity = 0.0f;
}
else
{
Crouch();
PostProcessVolume->Settings.VignetteIntensity = 0.8f;
}
}
// Called every frame
void ATempCharacter::Tick(float DeltaTime)
@ -53,6 +79,9 @@ void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo
PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput);
PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput);
PlayerInputComponent->BindAction(TEXT("Jump"), IE_Pressed, this, &ATempCharacter::Jump);
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);
}
@ -62,6 +91,8 @@ void ATempCharacter::KeyPressed()
LineTraceLogic();
}
// Line trace logic
void ATempCharacter::LineTraceLogic()
{
@ -140,14 +171,17 @@ void ATempCharacter::LineTraceLogic()
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;
//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)
{
return;
@ -157,21 +191,24 @@ void ATempCharacter::InputDisabler()
OriginalCameraLocation = ThisCamera->GetComponentLocation();
OriginalCameraRotation = ThisCamera->GetComponentRotation();
OriginalCameraFOV = ThisCamera->FieldOfView;
//ulog the originalcameralocation value
UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString());
}
}
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"));
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;
if (ThisCamera == nullptr)
{
@ -182,7 +219,6 @@ void ATempCharacter::InputEnabler()
ThisCamera->SetWorldLocation(OriginalCameraLocation);
ThisCamera->SetWorldRotation(OriginalCameraRotation);
ThisCamera->FieldOfView = OriginalCameraFOV;
//ulog the originalcameralocation value
UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString());
}
}
@ -192,7 +228,7 @@ void ATempCharacter::UseItem(class UBaseItem* Item)
if(Item)
{
Item->Use(this);
Item->OnUse(this); //Blueprint Version
Item->OnUse(this); //OnUse is a Blueprint Version
}
}

View File

@ -7,6 +7,7 @@
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
#include "Camera/CameraComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "Engine/PostProcessVolume.h"
#include "TempCharacter.generated.h"
UCLASS()
@ -25,6 +26,12 @@ protected:
void ForwardInput(float Axis);
void RightMoveInput(float Axis);
UFUNCTION()
void Sneak();
UCapsuleComponent* PlayerCapsule;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
@ -80,5 +87,6 @@ public:
UPROPERTY(BlueprintReadWrite)
bool disableTab = false;
APostProcessVolume* PostProcessVolume;
};