Start working on character
This commit is contained in:
parent
7e9436f8f2
commit
96c3f9121b
54
Source/LandOfBarl/LBCharacter.cpp
Normal file
54
Source/LandOfBarl/LBCharacter.cpp
Normal file
@ -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<FVector2D>();
|
||||
|
||||
if (Controller) {
|
||||
AddMovementInput(GetActorForwardVector(), MovementVector.Y);
|
||||
AddMovementInput(GetActorRightVector(), MovementVector.X);
|
||||
}
|
||||
}
|
||||
|
||||
void ALBCharacter::Look(const FInputActionValue& Value) {
|
||||
const auto LookAxisVector = Value.Get<FVector2D>();
|
||||
|
||||
if (Controller) {
|
||||
AddControllerYawInput(LookAxisVector.X);
|
||||
AddControllerPitchInput(LookAxisVector.Y);
|
||||
}
|
||||
}
|
||||
|
||||
void ALBCharacter::NotifyControllerChanged() {
|
||||
Super::NotifyControllerChanged();
|
||||
|
||||
if (auto* PlayerController = Cast<APlayerController>(Controller)) {
|
||||
if (auto* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer())) {
|
||||
Subsystem->AddMappingContext(DefaultMappingContext, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ALBCharacter::SetupPlayerInputComponent(UInputComponent* InputComponent) {
|
||||
if (auto* EnhancedInputComponent = Cast<UEnhancedInputComponent>(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<UCameraComponent>(TEXT("FirstPersonCamera"));
|
||||
FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
|
||||
FirstPersonCameraComponent->SetRelativeLocation(FVector(-10.f, 0.f, 60.f));
|
||||
FirstPersonCameraComponent->bUsePawnControlRotation = true;
|
||||
}
|
38
Source/LandOfBarl/LBCharacter.h
Normal file
38
Source/LandOfBarl/LBCharacter.h
Normal file
@ -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<UCameraComponent> FirstPersonCameraComponent;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
TObjectPtr<UInputMappingContext> DefaultMappingContext;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
TObjectPtr<UInputAction> JumpAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
TObjectPtr<UInputAction> MoveAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
TObjectPtr<UInputAction> LookAction;
|
||||
protected:
|
||||
void Move(const FInputActionValue& Value);
|
||||
void Look(const FInputActionValue& Value);
|
||||
|
||||
virtual void NotifyControllerChanged() override;
|
||||
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
|
||||
public:
|
||||
ALBCharacter();
|
||||
};
|
5
Source/LandOfBarl/LBGameMode.cpp
Normal file
5
Source/LandOfBarl/LBGameMode.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "LBGameMode.h"
|
||||
|
||||
ALBGameMode::ALBGameMode() {
|
||||
|
||||
}
|
12
Source/LandOfBarl/LBGameMode.h
Normal file
12
Source/LandOfBarl/LBGameMode.h
Normal file
@ -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();
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user