Skip to content
Snippets Groups Projects
Commit d38ea787 authored by Ehret's avatar Ehret
Browse files

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

parent 4f2ed7ce
No related branches found
No related tags found
No related merge requests found
......@@ -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