Hi Guys.
Please understand my english is not that good cuz from South Korea.
plus newbie of UE4 C++
First of all, thank you are seeing this question.
I have some problems on my VR project.
I’m using Oculus Rift S for this project.
Both hands are moving for left controller, and right controller is not working.
Since the devices are completely connected.
Is the any problems in my code?
VRPawn.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Camera/CameraComponent.h"
#include "Components/TextRenderComponent.h"
#include "MotionControllerComponent.h"
#include "VRPawn.generated.h"
UCLASS()
class CAPSTON_1_API AVRPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AVRPawn();
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
//Setting VR
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
USceneComponent* VRTrackingCenter;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UCameraComponent* VRCameraComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UTextRenderComponent* OutputText;
//MotionControllerComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UMotionControllerComponent* LeftController;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UMotionControllerComponent* RightController;
//StaticMeshComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UStaticMeshComponent* LeftSword;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
USkeletalMeshComponent* LeftHand;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
UStaticMeshComponent* RightSword;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = __hide)
USkeletalMeshComponent* RightHand;
};
VRPawn.cpp
#include "VRPawn.h"
#include "MotioncontrollerComponent.h"
#include "XRMotionControllerBase.h"
// Sets default values
AVRPawn::AVRPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
VRTrackingCenter = CreateDefaultSubobject<USceneComponent>(TEXT("VRTrackingCenter"));
VRCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("VRCameraComponent"));
OutputText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("OutputText"));
LeftController = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("LeftController"));
LeftController->MotionSource = FXRMotionControllerBase::LeftHandSourceId;
LeftSword = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("LeftSword"));
LeftHand = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("LeftHand"));
RightController = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("RightConterller"));
RightController->MotionSource = FXRMotionControllerBase::RightHandSourceId;
RightSword = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RightSword"));
RightHand = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("RightHand"));
VRCameraComponent->SetupAttachment(VRTrackingCenter);
OutputText->SetupAttachment(VRCameraComponent);
LeftController->SetupAttachment(VRTrackingCenter);
LeftHand->SetupAttachment(LeftController);
LeftSword->SetupAttachment(LeftHand);
RightController->SetupAttachment(VRTrackingCenter);
RightHand->SetupAttachment(RightController);
RightSword->SetupAttachment(RightHand);
}
// Called when the game starts or when spawned
void AVRPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AVRPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}```
Thanks all.