Weird with Actor Hand controller

i am using unreal engine 4.27.2
with oculus quest 2

VR character .cpp
![VRLearn - Microsoft Visual Studio 29-03-2022 18_06_06|690x370]
(upload://4KKNIi246XeKLvT2ZfrQ8Ygwaw.png)

VR character .h


HandComponent.Cpp

HandComponent.h


while play
controller is not tracking , no more character movement by thumbstick , teleporting in same place

1 Like

Hi Ashok,
First, when sharing source, can you use the < / > formatter and paste the code. Screenshots of code is not helpful.

When you use a custom class, one step you need to add when creating the instance is to set the owner i.e. TheLeftController->SetOwner(this);

It’s only needed when you set up your own controller class.

thank you it working careless mistake by me even error didn’t occurred but now teleportation is not working

bool AVRCharacter::FindTeleportDestination(TArray& OutPath, FVector& OutLocation)
{
FVector Look = TheRightController->GetActorForwardVector() * TeleportProjectileSpeed;
FVector Location = TheRightController->GetActorLocation(); //+ Look* 10.;

FPredictProjectilePathParams Params(TeleportProjectileRadius, Location, Look, 
        TeleportSimulationTime, ECollisionChannel::ECC_Visibility,this);
Params.DrawDebugType = EDrawDebugTrace::ForOneFrame;
Params.bTraceComplex = true;

FPredictProjectilePathResult Result;

bool bSucess = UGameplayStatics::PredictProjectilePath(this, Params, Result);

if (!bSucess) return false;

for (FPredictProjectilePathPointData PointData : Result.PathData)
{
	//FPredictProjectilePathPointData has its built variable Location,time,velocity i took location
	OutPath.Add(PointData.Location);
};

FNavLocation Navigation;

bool bNavigative = UNavigationSystemV1::GetCurrent(GetWorld())->ProjectPointToNavigation(Result.HitResult.Location, Navigation, TeleportationExtent);
if (!bNavigative)return false;
OutLocation = Navigation.Location;

return true;

}

There are a few differences here.

Look should be a unit vector so just the result of TheRightController->GetActorForwardVector() and not multiplied by the teleport speed. This upsets the next calculation, the start location, and this should should be something like
FVector startVector = RightMotionController->GetComponentLocation() + look * 15.0f;

You then set the parameter in the Params to Look * TeleportSpeed instead of just Look

The rest seems ok

no it’s not working

Can you share the modified code. Remember, for your location, add the Look*10.0f which distances the start from the controller preventing a collision.

bool AVRCharacter::FindTeleportDestination(TArray& OutPath, FVector& OutLocation)
{
FVector Look = TheRightController->GetActorForwardVector();
FVector Location = TheRightController->GetActorLocation() + Look *15.0f;

FPredictProjectilePathParams Params(TeleportProjectileRadius, Location, Look * TeleportProjectileSpeed, TeleportSimulationTime, ECollisionChannel::ECC_Visibility,this);
Params.DrawDebugType = EDrawDebugTrace::ForOneFrame;
Params.bTraceComplex = true;

FPredictProjectilePathResult Result;

bool bSucess = UGameplayStatics::PredictProjectilePath(this, Params, Result);

if (!bSucess) return false;
												
for (FPredictProjectilePathPointData PointData : Result.PathData)
{
	OutPath.Add(PointData.Location);
};

FNavLocation Navigation;

bool bNavigative = UNavigationSystemV1::GetCurrent(GetWorld())->ProjectPointToNavigation(Result.HitResult.Location, Navigation, TeleportationExtent);
if (!bNavigative)return false;

OutLocation = Navigation.Location;

return true;

}

Ok, This may be something but I remember having issues with ECC_Visibility and changed to use ECC_MAX to resolve the issue. This could be the problem

Sorry, just spotted another issue.
The Nav System code isn’t quite right. Try this:

  FNavLocation outNavLocation;
  UNavigationSystemV1* pNavSystem = UNavigationSystemV1::GetNavigationSystem( GetWorld() );
  result = pNavSystem->ProjectPointToNavigation( pathResult.HitResult.Location, outNavLocation, TeleportExtents );

no sir, it’s not working

I’ll share my code. The code for me is working perfectly. The method name doesn’t match but it’s basically the same code. Screenshot below as well.

If this isn’t working, close your editor and delete the binaries and Intermediate folder then launch the uproject again.

At this point it should be working. I should note my project is 4.26 but there should be little difference between the 2 projects.

bool AVRCharacter::GetTeleportLocation( FVector& OutLocation )
{
  OutLocation = FVector::ZeroVector;

  //  calculate the direction in which the controller is pointing, applying a slight rotation to point the controller
  //  in the right direction. Use this instead of forward
  FVector Look = RightMotionController->GetForwardVector();

  //  the start and end vectors for the line trace
  FVector startVector = RightMotionController->GetComponentLocation();

  //  we have a hit, so we can teleport.
  FPredictProjectilePathParams inParams( TeleportRadius, startVector, Look * TeleportSpeed, TeleportSimTime, ECollisionChannel::ECC_MAX, this  );
  inParams.DrawDebugType = EDrawDebugTrace::ForOneFrame;
  FPredictProjectilePathResult PathResult;

  bool bDidHit = UGameplayStatics::PredictProjectilePath( this, inParams, PathResult );

  if ( !bDidHit )
  {
    return false;
  }
  //UE_LOG( LogTemp, Warning, TEXT("HIT: %s"), *( hitResult.Location.ToString() ) );

  FNavLocation OutNavLocation;
  UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem( GetWorld() );
  bool IsNavPossible = NavSystem->ProjectPointToNavigation( PathResult.HitResult.Location, OutNavLocation, TeleportExtents );
  if ( IsNavPossible )
  {
    OutLocation = OutNavLocation.Location;
  }
  return IsNavPossible;
}

why you didn’t change into actor instead component
GetComponentLocation() into GetActorLocation()

In the tests I have, I’ve not extracted the controller yet, which I realise is different from what you have. However, checking the code in the specific lecture I see the only change is in fact the position of the controller. So, talking my code, all you’d have to do is change the startVector and it should work.

Ashok,
Just so you know, I’ve checked my code after the HandController refactor. The 2 lines were updated to be the following (I also renamed the startVector to StartLocation)

  FVector Look = RightMotionController->GetActorForwardVector();
  FVector StartLocation = RightMotionController->GetActorLocation();

This worked exactly as it did before the refactor. One thing I did have to do is in the HandController class, I couldn’t use MotionController as the created Motion controller. I had to change the name to TheMotionController. Once I did this, the issues (crashes) went away.

Let me know if you’re having issues.

thank you so much worked

1 Like

help…

did you add UFUNCTION() above the declaration in the header?

yes i did

UFUNCTION()
void OnBeginOverlap(UPrimitiveComponent* OnComponentBeginOverlap, UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

Error

Privacy & Terms