Thanks for the reply mate,
I tried what you said but to no avail.
Just to describe my setup for a much better picture
My GameMode only has a constructor:
ATheTowerGameMode::ATheTowerGameMode()
{
DefaultPawnClass = ATheTowerCharacter::StaticClass();
PlayerControllerClass = ATowerPlayerController::StaticClass();
}
My TowerCharacter is the sidescroller c++ one, stripped back a little without the camera stuff:
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Character.h"
#include "TheTowerCharacter.generated.h"
UCLASS(config=Game)
class ATheTowerCharacter : public ACharacter
{
GENERATED_BODY()
protected:
/** Called for side to side input */
void MoveRight(float Val);
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// End of APawn interface
public:
ATheTowerCharacter();
virtual FRotator GetViewRotation() const override;
};
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "TheTower.h"
#include "TheTowerCharacter.h"
#include "TowerPlayerController.h"
ATheTowerCharacter::ATheTowerCharacter()
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// Don't rotate when the controller rotates.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Face in the direction we are moving..
GetCharacterMovement()->RotationRate = FRotator(0.0f, 720.0f, 0.0f); // ...at this rotation rate
GetCharacterMovement()->GravityScale = 2.f;
GetCharacterMovement()->AirControl = 0.80f;
GetCharacterMovement()->JumpZVelocity = 1000.f;
GetCharacterMovement()->GroundFriction = 3.f;
GetCharacterMovement()->MaxWalkSpeed = 600.f;
GetCharacterMovement()->MaxFlySpeed = 600.f;
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
}
//////////////////////////////////////////////////////////////////////////
// Input
void ATheTowerCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
// set up gameplay key bindings
InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
InputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
InputComponent->BindAxis("MoveRight", this, &ATheTowerCharacter::MoveRight);
InputComponent->BindTouch(IE_Pressed, this, &ATheTowerCharacter::TouchStarted);
InputComponent->BindTouch(IE_Released, this, &ATheTowerCharacter::TouchStopped);
}
void ATheTowerCharacter::MoveRight(float Value)
{
// add movement in that direction
AddMovementInput(FVector(0.f,-1.f,0.f), Value);
}
FRotator ATheTowerCharacter::GetViewRotation() const
{
if (ATowerPlayerController* MYPC = Cast<ATowerPlayerController>(Controller))
{
return MYPC->GetViewRotation();
}
else if (Role < ROLE_Authority)
{
// check if being spectated
for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
{
APlayerController* PlayerController = *Iterator;
if (PlayerController && PlayerController->PlayerCameraManager->GetViewTargetPawn() == this)
{
return PlayerController->BlendedTargetViewRotation;
}
}
}
return GetActorRotation();
}
My Player Controller Class
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/PlayerController.h"
#include "TowerPlayerController.generated.h"
/**
*
*/
UCLASS()
class THETOWER_API ATowerPlayerController : public APlayerController
{
GENERATED_BODY()
public:
ATowerPlayerController();
virtual void UpdateRotation(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category = "Pawn")
FRotator GetViewRotation() const;
UFUNCTION(BlueprintCallable, Category = "Pawn")
virtual void SetViewRotation(const FRotator& NewRotation);
virtual void SetControlRotation(const FRotator& NewRotation) override;
protected:
/**
* View & Movement direction are now separate.
* The controller rotation will determine which direction we will move.
* ViewRotation represents where we are looking.
*/
UPROPERTY()
FRotator ViewRotation;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "TheTower.h"
#include "TowerPlayerController.h"
#include "TowerCameraManager.h"
// Make sure you include this!!
#include "IHeadMountedDisplay.h"
ATowerPlayerController::ATowerPlayerController()
{
bAutoManageActiveCameraTarget = false;
PlayerCameraManagerClass = ATowerCameraManager::StaticClass();
}
void ATowerPlayerController::UpdateRotation(float DeltaTime)
{
// Calculate Delta to be applied on ViewRotation
FRotator DeltaRot(RotationInput);
FRotator NewControlRotation = GetControlRotation();
if (PlayerCameraManager)
{
PlayerCameraManager->ProcessViewRotation(DeltaTime, NewControlRotation, DeltaRot);
}
SetControlRotation(NewControlRotation);
if (!PlayerCameraManager || !PlayerCameraManager->bFollowHmdOrientation)
{
if (GEngine->HMDDevice.IsValid() && GEngine->HMDDevice->IsHeadTrackingAllowed())
{
FQuat HMDOrientation;
FVector HMDPosition;
// Disable bUpdateOnRT if using this method.
GEngine->HMDDevice->GetCurrentOrientationAndPosition(HMDOrientation, HMDPosition);
FRotator NewViewRotation = HMDOrientation.Rotator();
// Only keep the yaw component from the controller.
NewViewRotation.Yaw += NewControlRotation.Yaw;
SetViewRotation(NewViewRotation);
}
}
APawn* const P = GetPawnOrSpectator();
if (P)
{
P->FaceRotation(NewControlRotation, DeltaTime);
}
}
void ATowerPlayerController::SetControlRotation(const FRotator& NewRotation)
{
ControlRotation = NewRotation;
// Anything that is overriding view rotation will need to
// call SetViewRotation() after SetControlRotation().
SetViewRotation(NewRotation);
if (RootComponent && RootComponent->bAbsoluteRotation)
{
RootComponent->SetWorldRotation(GetControlRotation());
}
}
void ATowerPlayerController::SetViewRotation(const FRotator& NewRotation)
{
ViewRotation = NewRotation;
}
FRotator ATowerPlayerController::GetViewRotation() const
{
return ViewRotation;
}
Finally my camera manager class ONLY has a constructor and it is only this:
ATowerCameraManager::ATowerCameraManager()
{
bFollowHmdOrientation = true;
}
If you look at my screenshots, I have 2: one shows where the camera is, ‘attached’ on the player, and the other describes Ideally what I am trying to do.
I want the camera decoupled from the player, hopefully it’s own component and it sits in the same position and uses oculus to rotate and view the scene…
Does that explain it a little better?
Im about 6 months new to Unreal, but a seasoned dev in my professional life so I am hoping for some best practice guidance here!
Cheers again