RealDocs

ACharacter::GetGravityDirection

function Engine Since 5.4
#include "GameFramework/Character.h"
Access: public Specifiers: virtualconstoverride

Description

Returns the current world-space gravity direction vector for this character. Under standard gravity this is `(0, 0, -1)`, but returns the custom gravity direction when using the CharacterMovement custom gravity feature.

Caveats & Gotchas

  • This override queries `CharacterMovementComponent` for the active gravity direction, which can differ from the world default if you've set a custom gravity direction on the movement component. The simulated proxy version returns `ReplicatedGravityDirection`, which may lag by one replication tick.
  • The returned vector is normalized when using custom gravity, but for default gravity the engine returns exactly `(0, 0, -1)` — do not assume unit length without normalizing if you mix standard and custom gravity in the same project.
  • Custom gravity direction support was introduced to support wall-walking and planetary gravity scenarios. Using this on characters not configured for custom gravity returns the default downward vector with no overhead.

Signature

ENGINE_API virtual FVector GetGravityDirection() const override

Return Type

FVector

Example

Orient a projectile launch relative to the character's gravity C++
FVector AMyCharacter::GetLaunchDirection() const
{
	// Launch perpendicular to gravity (i.e. horizontally relative to the character)
	FVector GravDir = GetGravityDirection();
	FVector Forward = GetActorForwardVector();
	return FVector::VectorPlaneProject(Forward, GravDir).GetSafeNormal();
}

Version History

Introduced in: 5.4

Version Status Notes
5.6 stable
5.4 stable Custom gravity direction feature introduced.

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.