Hi,
I’m currently using UE5 to create a VR environment. As a result I’m creation some locomotion in for it using C++ but as a result when I implement it (followed tutorials etc) it doesn’t work.
I’ve set up the Axis Mapping correctly and as a result it either moves to in one direction and not the other or just moves opposite to what is already being inputted.
I’m currently using the HTC Vive and it’s just unusual as I feel that the input has been specified correctly for it so then as a result it should be allowing for the correct movement.
Thank you for any input that is able to be given on this issue which I’m having.
.h file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/InputComponent.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"
UCLASS()
class LYTTLETON_TUNNEL_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMyCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
.cpp file
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
// Sets default values
AMyCharacter::AMyCharacter()
{
// 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;
AutoPossessPlayer = EAutoReceiveInput::Player0;
//Setting class variables of the Character movement component
GetCharacterMovement()->bOrientRotationToMovement = false;
GetCharacterMovement()->bUseControllerDesiredRotation = true;
GetCharacterMovement()->bIgnoreBaseRotation = true;
GetCharacterMovement()->MaxWalkSpeed = 50.0f;
}
// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector PlayerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
}
// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//VR Input
InputComponent->BindAxis("HorizontalVR", this, &AMyCharacter::MoveForward);
InputComponent->BindAxis("VerticalVR", this, &AMyCharacter::MoveRight);
//Keyboard Input
InputComponent->BindAxis("HorizontalKeyboard", this, &AMyCharacter::MoveForward);
InputComponent->BindAxis("VerticalKeyboard", this, &AMyCharacter::MoveRight);
}
void AMyCharacter::MoveForward(float AxisValue)
{
if((Controller != nullptr) && (AxisValue != 0.0f))
{
//Find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
//Get forward Vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, AxisValue);
}
}
void AMyCharacter::MoveRight(float AxisValue)
{
if((Controller != nullptr) && (AxisValue != 0.0f))
{
//Find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
//Get right rotation
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, AxisValue);
}
}