Obtains the gravity vector that influences a SceneComponent.
336{
337 SCOPE_CYCLE_COUNTER(STAT_PhysicsVolumeGetGravity);
339 {
340 return FVector::ZeroVector;
341 }
342 FVector Gravity = FVector::ZeroVector;
343
345 {
347 {
349 break;
350 }
351
353 {
354 USplineComponent*
Spline =
nullptr;
356 {
357 Spline = Cast<USplineComponent>(
358 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
359 }
360 else
361 {
362 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
363 }
364
366 {
367 const FVector
Point = SceneComponent->GetComponentLocation();
368 const FVector GravityDir =
Spline->FindDirectionClosestToWorldLocation(
369 Point, ESplineCoordinateSpace::Type::World);
370 if (!GravityDir.IsZero())
371 {
373 }
374
375#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
377 {
378 DrawDebugDirectionalArrow(GetWorld(),
Point,
Point + GravityDir * 100.0f,
379 1000.0f, FColor::Green, false, 0.02f, 0, 4.0f);
380 }
381#endif
382 }
383
384 break;
385 }
386
388 {
390
392 {
394 }
395
396 const FVector GravityDir = GravityPoint - SceneComponent->GetComponentLocation();
397 if (!GravityDir.IsZero())
398 {
399 Gravity = GravityDir.GetSafeNormal() *
401 }
402
403#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
405 {
406 DrawDebugSphere(GetWorld(), GravityPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
407 }
408#endif
409
410 break;
411 }
412
414 {
415 const FVector
Point = SceneComponent->GetComponentLocation();
416 const FVector GravityDir = FMath::ClosestPointOnInfiniteLine(
418 if (!GravityDir.IsZero())
419 {
420 Gravity = GravityDir.GetSafeNormal() *
422 }
423
424#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
426 {
429 DrawDebugSphere(GetWorld(),
GravityVectorA, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
430 DrawDebugSphere(GetWorld(),
GravityVectorB, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
431 }
432#endif
433
434 break;
435 }
436
438 {
439 const FVector
Point = SceneComponent->GetComponentLocation();
440 const FVector GravityDir = FMath::ClosestPointOnLine(
GravityVectorA,
442 if (!GravityDir.IsZero())
443 {
444 Gravity = GravityDir.GetSafeNormal() *
446 }
447
448#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
450 {
452 DrawDebugSphere(GetWorld(),
GravityVectorA, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
453 DrawDebugSphere(GetWorld(),
GravityVectorB, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
454 }
455#endif
456
457 break;
458 }
459
461 {
462 USplineComponent*
Spline =
nullptr;
464 {
465 Spline = Cast<USplineComponent>(
466 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
467 }
468 else
469 {
470 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
471 }
472
474 {
475 const FVector
Point = SceneComponent->GetComponentLocation();
476 const FVector GravityPoint =
Spline->FindLocationClosestToWorldLocation(
477 Point, ESplineCoordinateSpace::Type::World);
478 const FVector GravityDir = GravityPoint -
Point;
479 if (!GravityDir.IsZero())
480 {
481 Gravity = GravityDir.GetSafeNormal() *
483 }
484
485#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
487 {
488 DrawDebugSphere(GetWorld(), GravityPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
489 }
490#endif
491 }
492
493 break;
494 }
495
497 {
498 const FVector
Point = SceneComponent->GetComponentLocation();
499 const FVector GravityDir = FVector::PointPlaneProject(
Point,
501 if (!GravityDir.IsZero())
502 {
503 Gravity = GravityDir.GetSafeNormal() *
505 }
506
507#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
509 {
511 FVector2D(500.0f, 500.0f), FColor::Green);
512 }
513#endif
514
515 break;
516 }
517
519 {
520 USplineComponent*
Spline =
nullptr;
522 {
523 Spline = Cast<USplineComponent>(
524 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
525 }
526 else
527 {
528 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
529 }
530
532 {
533 const FVector
Point = SceneComponent->GetComponentLocation();
534
535 const float InputKey =
Spline->FindInputKeyClosestToWorldLocation(
Point);
536 const FVector ClosestLocation =
Spline->GetLocationAtSplineInputKey(
537 InputKey, ESplineCoordinateSpace::Type::World);
538 const FVector ClosestUpVector =
Spline->GetUpVectorAtSplineInputKey(
539 InputKey, ESplineCoordinateSpace::Type::World);
540
541 const FVector GravityDir = FVector::PointPlaneProject(
Point,
542 ClosestLocation, ClosestUpVector) -
Point;
543 if (!GravityDir.IsZero())
544 {
545 Gravity = GravityDir.GetSafeNormal() *
547 }
548
549#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
551 {
552 DrawDebugSolidPlane(GetWorld(), FPlane(ClosestLocation, ClosestUpVector),
553 ClosestLocation, FVector2D(500.0f, 500.0f), FColor::Green);
554 }
555#endif
556 }
557
558 break;
559 }
560
562 {
565
567 {
568 GravityActor->GetActorBounds(
true, BoxOrigin, BoxExtent);
569 }
570
571 const FVector
Point = SceneComponent->GetComponentLocation();
572 const FVector GravityDir = FBox(BoxOrigin - BoxExtent,
573 BoxOrigin + BoxExtent).GetClosestPointTo(
Point) -
Point;
574 if (!GravityDir.IsZero())
575 {
576 Gravity = GravityDir.GetSafeNormal() *
578 }
579
580#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
582 {
583 DrawDebugSolidBox(GetWorld(), BoxOrigin, BoxExtent, FColor::Green);
584 }
585#endif
586
587 break;
588 }
589
591 {
593 {
594 const FVector
Point = SceneComponent->GetComponentLocation();
595
596 FVector ClosestPoint;
597 if (Cast<UPrimitiveComponent>(
GravityActor->GetRootComponent())->GetClosestPointOnCollision(
598 Point, ClosestPoint) > 0.0f)
599 {
600 const FVector GravityDir = ClosestPoint -
Point;
601 if (!GravityDir.IsZero())
602 {
603 Gravity = GravityDir.GetSafeNormal() *
605 }
606
607#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
609 {
610 DrawDebugSphere(GetWorld(), ClosestPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
611 }
612#endif
613 }
614 }
615
616 break;
617 }
618 }
619
620#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
622 {
623 const FVector
Point = SceneComponent->GetComponentLocation();
624 DrawDebugDirectionalArrow(GetWorld(),
Point,
Point + Gravity, 1000.0f,
625 FColor::Red, false, 0.02f, 0, 7.0f);
626 }
627#endif
628
629 return Gravity;
630}
virtual float GetFinalGravityScale(class USceneComponent *SceneComponent) const
Definition GravityPhysicsVolume.cpp:850
static int32 ShowGravity
Definition GravityPhysicsVolume.cpp:36