void ACinemotusPlayerController::HandleMovementAbs(float DeltaTime, bool useHydraMotion = false) { APawn* pawn = GetPawn(); if (!pawn) { return; } //check velocities FVector velocity = useHydraMotion ? HydraLatestData->controllers[CAM_HAND].velocity : FVector::ZeroVector; FVector velRel = FVector(velocity); FRotationMatrix mat(GetControlRotation()); float scalar = 2.5; if (useHydraMotion) { FRotationMatrix cMat(HydraLatestData->controllers[CAM_HAND].rotation); velRel.X = FVector::DotProduct(cMat.GetScaledAxis(EAxis::X), velocity); velRel.Y = FVector::DotProduct(cMat.GetScaledAxis(EAxis::Y), velocity); velRel.Z = FVector::DotProduct(cMat.GetScaledAxis(EAxis::Z), velocity); //take motion and make relative to the orientation of the controller } //velocity.X*DeltaTime * scaleCmToMetres*fSpeedMulitplier + pawn->AddMovementInput(mat.GetScaledAxis(EAxis::X), velRel.X*DeltaTime * scalar*fSpeedMulitplier + vXYandCrane.X); pawn->AddMovementInput(mat.GetScaledAxis(EAxis::Y), velRel.Y*DeltaTime * scalar*fSpeedMulitplier + vXYandCrane.Y); pawn->AddMovementInput(mat.GetScaledAxis(EAxis::Z), velRel.Z*DeltaTime * scalar*fSpeedMulitplier); pawn->AddMovementInput(FVector::UpVector, vXYandCrane.Z); //Add Movement input for offhand FVector xPlanar = mat.GetScaledAxis(EAxis::X); xPlanar.Z = 0; bool didNorm = xPlanar.Normalize(); if (!didNorm) { xPlanar.X = 1.0; xPlanar.Normalize(); } pawn->AddMovementInput(xPlanar, offHandPlanarMovement.X); FVector yPlanar = mat.GetScaledAxis(EAxis::Y); yPlanar.Z = 0; didNorm = yPlanar.Normalize(); if (!didNorm) { yPlanar.Y = 1.0; yPlanar.Normalize(); } pawn->AddMovementInput(yPlanar, offHandPlanarMovement.Y); }
void UBTTask_FlyTo::TickPathNavigation(UBehaviorTreeComponent& OwnerComp, FBT_FlyToTarget* MyMemory, float DeltaSeconds) { const auto& queryResults = MyMemory->QueryResults; APawn* pawn = OwnerComp.GetAIOwner()->GetPawn(); if (DebugParams.bVisualizePawnAsVoxels) NavigationManager->Debug_DrawVoxelCollisionProfile(Cast<UPrimitiveComponent>(pawn->GetRootComponent())); FVector flightDirection = queryResults.PathSolutionOptimized[MyMemory->solutionTraversalIndex] - pawn->GetActorLocation(); //auto navigator = Cast<IDonNavigator>(pawn); // Add movement input: if (MyMemory->bIsANavigator) { // Customized movement handling for advanced users: IDonNavigator::Execute_AddMovementInputCustom(pawn, flightDirection, 1.f); } else { // Default movement (handled by Pawn or Character class) pawn->AddMovementInput(flightDirection, 1.f); } FVector test = FVector(10,10,100); //test. // Reached next segment: if (flightDirection.Size() <= MinimumProximityRequired) { // Goal reached? if (MyMemory->solutionTraversalIndex == queryResults.PathSolutionOptimized.Num() - 1) { UBlackboardComponent* blackboard = pawn->GetController()->FindComponentByClass<UBlackboardComponent>(); blackboard->SetValueAsBool(FlightResultKey.SelectedKeyName, true); blackboard->SetValueAsBool(KeyToFlipFlopWhenTaskExits.SelectedKeyName, !blackboard->GetValueAsBool(KeyToFlipFlopWhenTaskExits.SelectedKeyName)); // Unregister all dynamic collision listeners. We've completed our task and are no longer interested in listening to these: NavigationManager->StopListeningToDynamicCollisionsForPath(MyMemory->DynamicCollisionListener, queryResults); FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded); return; } else { MyMemory->solutionTraversalIndex++; } } }