Skip to content
Snippets Groups Projects
Commit 6a431c1c authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Merge branch 'fix/VR_movement' into 'develop'

Use head instead of camera to get the head's position in VRPawnMovement

See merge request VR-Group/unreal-development/ndisplayextensions!34
parents 3fdb8b79 d38ea787
No related branches found
No related tags found
1 merge request!34Use head instead of camera to get the head's position in VRPawnMovement
......@@ -42,7 +42,7 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
LastCameraPosition = CameraComponent->GetComponentLocation();
LastHeadPosition = HeadComponent->GetComponentLocation();
}
bool UVRPawnMovement::CheckForVirtualMovCollision(FVector PositionChange, float DeltaTime)
......@@ -57,15 +57,15 @@ bool UVRPawnMovement::CheckForVirtualMovCollision(FVector PositionChange, float
return false;
}
void UVRPawnMovement::SetCameraComponent(UCameraComponent* NewCameraComponent)
void UVRPawnMovement::SetHeadComponent(USceneComponent* NewHeadComponent)
{
CameraComponent = NewCameraComponent;
CapsuleColliderComponent->SetupAttachment(CameraComponent);
HeadComponent = NewHeadComponent;
CapsuleColliderComponent->SetupAttachment(HeadComponent);
}
void UVRPawnMovement::SetCapsuleColliderToUserSize()
{
float CharachterSize = abs(UpdatedComponent->GetComponentLocation().Z - CameraComponent->GetComponentLocation().Z);
float CharachterSize = abs(UpdatedComponent->GetComponentLocation().Z - HeadComponent->GetComponentLocation().Z);
if (CharachterSize > MaxStepHeight)
{
......@@ -81,21 +81,21 @@ void UVRPawnMovement::SetCapsuleColliderToUserSize()
CapsuleColliderComponent->SetCapsuleSize(ColliderRadius, ColliderHalfHeight);
}
CapsuleColliderComponent->SetWorldLocation(CameraComponent->GetComponentLocation());
CapsuleColliderComponent->SetWorldLocation(HeadComponent->GetComponentLocation());
CapsuleColliderComponent->AddWorldOffset(FVector(0, 0, -ColliderHalfHeight));
CapsuleColliderComponent->SetWorldRotation(FRotator(0, 0, 1));
}
else
{
CapsuleColliderComponent->SetWorldLocation(CameraComponent->GetComponentLocation());
CapsuleColliderComponent->SetWorldLocation(HeadComponent->GetComponentLocation());
CapsuleColliderComponent->SetWorldRotation(FRotator(0, 0, 1));
}
}
void UVRPawnMovement::CheckForPhysWalkingCollision()
{
FVector CurrentCameraPosition = CameraComponent->GetComponentLocation();
FVector Direction = CurrentCameraPosition - LastCameraPosition;
FVector CurrentHeadPosition = HeadComponent->GetComponentLocation();
FVector Direction = CurrentHeadPosition - LastHeadPosition;
FHitResult FHitResultPhys;
CapsuleColliderComponent->AddWorldOffset(Direction, true, &FHitResultPhys);
......
......@@ -27,14 +27,14 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial
CameraComponent->SetupAttachment(RootComponent);
CameraComponent->SetAbsolute();
PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement"));
PawnMovement->SetUpdatedComponent(RootComponent);
PawnMovement->SetCameraComponent(CameraComponent);
Head = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Head"));
Head->ProxyType = ETrackedComponentType::TCT_HEAD;
Head->SetupAttachment(RootComponent);
PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement"));
PawnMovement->SetUpdatedComponent(RootComponent);
PawnMovement->SetHeadComponent(Head);
RightHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Right Hand"));
RightHand->ProxyType = ETrackedComponentType::TCT_RIGHT_HAND;
RightHand->AttachementType = EAttachementType::AT_FLYSTICK;
......
......@@ -38,7 +38,7 @@ public:
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
void SetCameraComponent(UCameraComponent* NewCameraComponent);
void SetHeadComponent(USceneComponent* NewHeadComponent);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement")
EVRNavigationModes NavigationMode = EVRNavigationModes::NAV_WALK;
......@@ -63,8 +63,8 @@ private:
//(direction = Down = -1), (direction = Up = 1)
UPROPERTY() UCapsuleComponent* CapsuleColliderComponent = nullptr;
UPROPERTY() UCameraComponent* CameraComponent = nullptr;
UPROPERTY() USceneComponent* HeadComponent = nullptr;
float VerticalSpeed = 0.0f;
FVector LastCameraPosition;
FVector LastHeadPosition;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment