diff --git a/Source/LandOfBarl/LBCharacter.cpp b/Source/LandOfBarl/LBCharacter.cpp new file mode 100644 index 0000000..6260b17 --- /dev/null +++ b/Source/LandOfBarl/LBCharacter.cpp @@ -0,0 +1,54 @@ +#include "LBCharacter.h" +#include "Camera/CameraComponent.h" +#include "Components/CapsuleComponent.h" +#include "EnhancedInputComponent.h" +#include "EnhancedInputSubsystems.h" +#include "InputActionValue.h" + +void ALBCharacter::Move(const FInputActionValue& Value) { + const auto MovementVector = Value.Get(); + + if (Controller) { + AddMovementInput(GetActorForwardVector(), MovementVector.Y); + AddMovementInput(GetActorRightVector(), MovementVector.X); + } +} + +void ALBCharacter::Look(const FInputActionValue& Value) { + const auto LookAxisVector = Value.Get(); + + if (Controller) { + AddControllerYawInput(LookAxisVector.X); + AddControllerPitchInput(LookAxisVector.Y); + } +} + +void ALBCharacter::NotifyControllerChanged() { + Super::NotifyControllerChanged(); + + if (auto* PlayerController = Cast(Controller)) { + if (auto* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) { + Subsystem->AddMappingContext(DefaultMappingContext, 0); + } + } +} + +void ALBCharacter::SetupPlayerInputComponent(UInputComponent* InputComponent) { + if (auto* EnhancedInputComponent = Cast(InputComponent)) { + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump); + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); + + EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ALBCharacter::Move); + + EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALBCharacter::Look); + } +} + +ALBCharacter::ALBCharacter() { + GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); + + FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera")); + FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent()); + FirstPersonCameraComponent->SetRelativeLocation(FVector(-10.f, 0.f, 60.f)); + FirstPersonCameraComponent->bUsePawnControlRotation = true; +} \ No newline at end of file diff --git a/Source/LandOfBarl/LBCharacter.h b/Source/LandOfBarl/LBCharacter.h new file mode 100644 index 0000000..3fe3c99 --- /dev/null +++ b/Source/LandOfBarl/LBCharacter.h @@ -0,0 +1,38 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "LBCharacter.generated.h" + +struct FInputActionValue; +class UCameraComponent; +class UInputAction; +class UInputMappingContext; + +UCLASS() +class LANDOFBARL_API ALBCharacter : public ACharacter { + GENERATED_BODY() + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) + TObjectPtr FirstPersonCameraComponent; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + TObjectPtr DefaultMappingContext; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + TObjectPtr JumpAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + TObjectPtr MoveAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + TObjectPtr LookAction; +protected: + void Move(const FInputActionValue& Value); + void Look(const FInputActionValue& Value); + + virtual void NotifyControllerChanged() override; + virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override; +public: + ALBCharacter(); +}; diff --git a/Source/LandOfBarl/LBGameMode.cpp b/Source/LandOfBarl/LBGameMode.cpp new file mode 100644 index 0000000..bc4af91 --- /dev/null +++ b/Source/LandOfBarl/LBGameMode.cpp @@ -0,0 +1,5 @@ +#include "LBGameMode.h" + +ALBGameMode::ALBGameMode() { + +} diff --git a/Source/LandOfBarl/LBGameMode.h b/Source/LandOfBarl/LBGameMode.h new file mode 100644 index 0000000..8cb8579 --- /dev/null +++ b/Source/LandOfBarl/LBGameMode.h @@ -0,0 +1,12 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "LBGameMode.generated.h" + +UCLASS() +class LANDOFBARL_API ALBGameMode : public AGameModeBase { + GENERATED_BODY() +public: + ALBGameMode(); +};