Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- node
- Bootstrap4
- 스터디
- flask
- 데이터베이스
- 파이썬서버
- Express
- 마인크래프트뮤지컬
- 언리얼뮤지컬
- VUE
- 정글사관학교
- EnhancedInput
- 프린세스메이커
- 카렌
- R
- Jinja2
- 언리얼프로그래머
- 미니프로젝트
- 프메
- 레베카
- Enhanced Input System
- 디자드
- 알고풀자
- JWT
- 게임개발
- 으
- 스마일게이트
- Ajax
- Unseen
- 언리얼
Archives
- Today
- Total
Showing
[Unreal, VR] Custom VR Pawn Blueprint 본문
우선 기본 vr pawn을 복제해준다.
복제한 My_VRPawn에다 여러가지 vr 플레이어 기능들을 커스텀해서 반영하기 위함이다.
! 부모 클래스를 캐릭터형으로 바꾸어준다!
왼쪽, 오른쪽 엄지 조이스틱으로 이동, 회전
왼쪽 엄지 조이스틱으로는 이동을 결정하게 해준다.
오른쪽 엄지 조이스틱으로는 회전을 담당하게 설정해준다.
위의 panw 구조를 직접 캐릭터 c++로 작성하고 싶다면 아래의 기본 틀을 가져가야 한다. VR Origin 구조를 캡슐 컴포넌트 아래에 만들어주고, 카메라와 왼손 오른손 컨트롤러를 그 아래에다가 계층이동 시켜주는 것이 핵심이다.
VRCharacter.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Camera/CameraComponent.h"
#include "VRCharacter.generated.h"
UCLASS()
class SESACVR_API AVRCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AVRCharacter();
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, Category = "Controller")
class UMotionControllerComponent* LeftController;
UPROPERTY(EditAnywhere, Category = "Controller")
class UMotionControllerComponent* RightController;
UPROPERTY(EditAnywhere, Category = "Input")
class UInputMappingContext* PlayerMappingContext;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HMD")
class UCameraComponent* CameraComp;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HMD")
class USceneComponent* VROrigin;
protected:
UPROPERTY(EditAnywhere, Category = "Input")
class UInputAction* IA_LeftThumbstick;
UPROPERTY(EditAnywhere, Category = "Input")
class UInputAction* IA_LeftTrigger;
UPROPERTY(EditAnywhere, Category = "Input")
class UInputAction* IA_RightThumbstick;
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION()
void Func1(const FInputActionValue& Value);
UFUNCTION()
void Func2(const FInputActionValue& Value);
UFUNCTION()
void Func3(const FInputActionValue& Value);
};
VRCharacter.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "VRCharacter.h"
#include "MotionControllerComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
#include "Components/SceneComponent.h"
#include "Components/ArrowComponent.h"
// Sets default values
AVRCharacter::AVRCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SetRootComponent(GetCapsuleComponent());
//GetCapsuleComponent()->SetCapsuleSize(1.f, 1.f);
GetMesh()->SetupAttachment(RootComponent);
GetArrowComponent()->SetupAttachment(RootComponent);
VROrigin = CreateDefaultSubobject<USceneComponent>(TEXT("VROrigin"));
VROrigin->SetupAttachment(RootComponent);
LeftController = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("LeftCon"));
LeftController->MotionSource = FName("Left");
LeftController->SetupAttachment(VROrigin);
RightController = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("RightCon"));
RightController->MotionSource = FName("Right");
RightController->SetupAttachment(VROrigin);
CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("HMD"));
CameraComp->SetupAttachment(VROrigin);
}
// Called when the game starts or when spawned
void AVRCharacter::BeginPlay()
{
Super::BeginPlay();
if (APlayerController* PlayerController = Cast<APlayerController>(GetController()))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem
= ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(PlayerMappingContext, 0);
}
}
}
// Called every frame
void AVRCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AVRCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
{
//EnhancedInputComponent->BindAction(IA_LeftThumbstick, ETriggerEvent::Triggered, this, &AVRCharacter::Func1);
//EnhancedInputComponent->BindAction(IA_LeftTrigger, ETriggerEvent::Triggered, this, &AVRCharacter::Func2);
//EnhancedInputComponent->BindAction(IA_RightThumbstick, ETriggerEvent::Triggered, this, &AVRCharacter::Func3);
}
}
void AVRCharacter::Func1(const FInputActionValue& Value)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("LeftThumbstick"));
}
void AVRCharacter::Func2(const FInputActionValue& Value)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("LeftTrigger"));
}
void AVRCharacter::Func3(const FInputActionValue& Value)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("RightThumbstick"));
}
'Unreal' 카테고리의 다른 글
[UE] 언리얼에서 3D 드로잉 기능이 구현된 에셋 (0) | 2023.12.27 |
---|---|
[Unreal] 언리얼 버추얼 프로덕션 virtual-production (1) | 2023.12.25 |
[Unreal, VR] VR에서 Item grab(Hold) and Release를 위한 블루프린트 설정 (1) | 2023.12.18 |
[Unreal] Line Trace를 이용하여 3D Player에서 NPC로의 시점 전환 (1) | 2023.11.28 |
[Unreal] Pawn과 Character, EnhancedInput vs InputSystem (0) | 2023.11.24 |