Obtains the gravity vector that influences a SceneComponent.
345{
346 SCOPE_CYCLE_COUNTER(STAT_PhysicsActorGetGravity);
348 {
349 return FVector::ZeroVector;
350 }
351 FVector Gravity = FVector::ZeroVector;
352
354 {
356 {
358 break;
359 }
360
362 {
363 USplineComponent*
Spline =
nullptr;
365 {
366 Spline = Cast<USplineComponent>(
367 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
368 }
369 else
370 {
371 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
372 }
373
375 {
376 const FVector
Point = SceneComponent->GetComponentLocation();
377 const FVector GravityDir =
Spline->FindDirectionClosestToWorldLocation(
378 Point, ESplineCoordinateSpace::Type::World);
379 if (!GravityDir.IsZero())
380 {
382 }
383
384#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
386 {
387 DrawDebugDirectionalArrow(GetWorld(),
Point,
Point + GravityDir * 100.0f,
388 1000.0f, FColor::Green, false, 0.02f, 0, 4.0f);
389 }
390#endif
391 }
392
393 break;
394 }
395
397 {
399
401 {
403 }
404
405 const FVector GravityDir = GravityPoint - SceneComponent->GetComponentLocation();
406 if (!GravityDir.IsZero())
407 {
408 Gravity = GravityDir.GetSafeNormal() *
410 }
411
412#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
414 {
415 DrawDebugSphere(GetWorld(), GravityPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
416 }
417#endif
418
419 break;
420 }
421
423 {
424 const FVector
Point = SceneComponent->GetComponentLocation();
425 const FVector GravityDir = FMath::ClosestPointOnInfiniteLine(
427 if (!GravityDir.IsZero())
428 {
429 Gravity = GravityDir.GetSafeNormal() *
431 }
432
433#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
435 {
438 DrawDebugSphere(GetWorld(),
GravityVectorA, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
439 DrawDebugSphere(GetWorld(),
GravityVectorB, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
440 }
441#endif
442
443 break;
444 }
445
447 {
448 const FVector
Point = SceneComponent->GetComponentLocation();
449 const FVector GravityDir = FMath::ClosestPointOnLine(
GravityVectorA,
451 if (!GravityDir.IsZero())
452 {
453 Gravity = GravityDir.GetSafeNormal() *
455 }
456
457#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
459 {
461 DrawDebugSphere(GetWorld(),
GravityVectorA, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
462 DrawDebugSphere(GetWorld(),
GravityVectorB, 4.0, 8, FColor::Blue,
false, 0.02f, 0, 10.0f);
463 }
464#endif
465
466 break;
467 }
468
470 {
471 USplineComponent*
Spline =
nullptr;
473 {
474 Spline = Cast<USplineComponent>(
475 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
476 }
477 else
478 {
479 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
480 }
481
483 {
484 const FVector
Point = SceneComponent->GetComponentLocation();
485 const FVector GravityPoint =
Spline->FindLocationClosestToWorldLocation(
486 Point, ESplineCoordinateSpace::Type::World);
487 const FVector GravityDir = GravityPoint -
Point;
488 if (!GravityDir.IsZero())
489 {
490 Gravity = GravityDir.GetSafeNormal() *
492 }
493
494#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
496 {
497 DrawDebugSphere(GetWorld(), GravityPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
498 }
499#endif
500 }
501
502 break;
503 }
504
506 {
507 const FVector
Point = SceneComponent->GetComponentLocation();
508 const FVector GravityDir = FVector::PointPlaneProject(
Point,
510 if (!GravityDir.IsZero())
511 {
512 Gravity = GravityDir.GetSafeNormal() *
514 }
515
516#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
518 {
520 FVector2D(500.0f, 500.0f), FColor::Green);
521 }
522#endif
523
524 break;
525 }
526
528 {
529 USplineComponent*
Spline =
nullptr;
531 {
532 Spline = Cast<USplineComponent>(
533 GravityActor->GetComponentByClass(USplineComponent::StaticClass()));
534 }
535 else
536 {
537 Spline = Cast<USplineComponent>(GetComponentByClass(USplineComponent::StaticClass()));
538 }
539
541 {
542 const FVector
Point = SceneComponent->GetComponentLocation();
543
544 const float InputKey =
Spline->FindInputKeyClosestToWorldLocation(
Point);
545 const FVector ClosestLocation =
Spline->GetLocationAtSplineInputKey(
546 InputKey, ESplineCoordinateSpace::Type::World);
547 const FVector ClosestUpVector =
Spline->GetUpVectorAtSplineInputKey(
548 InputKey, ESplineCoordinateSpace::Type::World);
549
550 const FVector GravityDir = FVector::PointPlaneProject(
Point,
551 ClosestLocation, ClosestUpVector) -
Point;
552 if (!GravityDir.IsZero())
553 {
554 Gravity = GravityDir.GetSafeNormal() *
556 }
557
558#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
560 {
561 DrawDebugSolidPlane(GetWorld(), FPlane(ClosestLocation, ClosestUpVector),
562 ClosestLocation, FVector2D(500.0f, 500.0f), FColor::Green);
563 }
564#endif
565 }
566
567 break;
568 }
569
571 {
574
576 {
577 GravityActor->GetActorBounds(
true, BoxOrigin, BoxExtent);
578 }
579
580 const FVector
Point = SceneComponent->GetComponentLocation();
581 const FVector GravityDir = FBox(BoxOrigin - BoxExtent,
582 BoxOrigin + BoxExtent).GetClosestPointTo(
Point) -
Point;
583 if (!GravityDir.IsZero())
584 {
585 Gravity = GravityDir.GetSafeNormal() *
587 }
588
589#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
591 {
592 DrawDebugSolidBox(GetWorld(), BoxOrigin, BoxExtent, FColor::Green);
593 }
594#endif
595
596 break;
597 }
598
600 {
602 {
603 const FVector
Point = SceneComponent->GetComponentLocation();
604
605 FVector ClosestPoint;
606 if (Cast<UPrimitiveComponent>(
GravityActor->GetRootComponent())->GetClosestPointOnCollision(
607 Point, ClosestPoint) > 0.0f)
608 {
609 const FVector GravityDir = ClosestPoint -
Point;
610 if (!GravityDir.IsZero())
611 {
612 Gravity = GravityDir.GetSafeNormal() *
614 }
615
616#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
618 {
619 DrawDebugSphere(GetWorld(), ClosestPoint, 4.0, 8, FColor::Green, false, 0.02f, 0, 10.0f);
620 }
621#endif
622 }
623 }
624
625 break;
626 }
627 }
628
629#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
631 {
632 const FVector
Point = SceneComponent->GetComponentLocation();
633 DrawDebugDirectionalArrow(GetWorld(),
Point,
Point + Gravity, 1000.0f,
634 FColor::Red, false, 0.02f, 0, 7.0f);
635 }
636#endif
637
638 return Gravity;
639}
float GetGravityZ() const
Definition GravityActor.cpp:117
virtual float GetFinalGravityScale(class USceneComponent *SceneComponent) const
Definition GravityActor.cpp:859
static int32 ShowGravity
Definition GravityActor.cpp:32