Destination marker not updating with motion controller

I’m having an issue with the teleport destination not properly updating when using the motion controller. I am calling LineTraceSingleByChannel, then ProjectPointToNavigation. The exact same code using the HMD camera does update the destination marker, so I don’t understand why this is behaving differently. I also posted a video on the Facebook page showing the behavior. I am using Unreal 4.24 with an Oculus Rift S.

bool AVRCharacter::FindTeleportDestinationController(FVector& OutLocation) const
{
	if (!DestinationMarker || !RightMotionController) return false;

	FHitResult HitResult;
	FVector Start = RightMotionController->GetComponentLocation();
	FVector LookVector = RightMotionController->GetForwardVector();

	LookVector = LookVector.RotateAngleAxis(30.f, RightMotionController->GetRightVector());
	FVector End = Start + LookVector * MaxTeleportDistance;

	bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECollisionChannel::ECC_Visibility);
	DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 0.0f, 0.0f, 2.0f);

	if (!bHit) return false;

	FNavLocation NavLocation;
	bool bOnNavMesh = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld())->ProjectPointToNavigation(HitResult.Location, NavLocation, TeleportProjectionExtent);
	
	if (!bOnNavMesh) return false;

	OutLocation = NavLocation.Location;

	return true;
}

I figured out what was causing the problem after adding some more logging. The line trace was going through the controller static mesh, so it was using that location when checking the navigation system. I fixed it by setting my starting point slightly in front of the controller. The updated code is below if anyone else encounters this in the future.

FVector LookVector = RightMotionController->GetForwardVector();
LookVector = LookVector.RotateAngleAxis(30.f, RightMotionController->GetRightVector());

FVector Start = RightMotionController->GetComponentLocation() + LookVector * 10.f;  // Start line trace in front of motion controller
FVector End = Start + LookVector * MaxTeleportDistance;
2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms