How to enable my custom Third PersonCharacter to walk on walls?

So, i already made a character in wich i can modify the gravity direction througt its movement component, i want to make some sort of “planetoids” and let my character walk there calculating the gravity direction in the tick(Yes, like mario galaxy). For testing im changing the character initial gravity direction to 1 in X and test first if he’s able to walk on the wall, the problem is he keeps falling, i think it has something to do with the way the character movement component knows if the character has landed as is able to walk or jump, etc. But i just cant find where should i modify this in c++.

Here’s my cpp file:

class UCharacterMovementComponent;

void ASpaceGravityCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (CurrentPlanet)
	{
		const FVector Dir = GetGravityDirection();
		GetCharacterMovement()->SetGravityDirection(Dir);
	}
}

void ASpaceGravityCharacter::BeginPlay()
{
	Super::BeginPlay();
	GetCharacterMovement()->SetGravityDirection(InitialGravityDirection);
}

void ASpaceGravityCharacter::SetCurrentPlanet(APlanetoid* NewPlanet)
{
	CurrentPlanet = NewPlanet;
}


FVector ASpaceGravityCharacter::CalculateGravityDirection()
{
	return CurrentPlanet->GetActorLocation() - GetActorLocation();;
}

Your concept is reminiscent of the gravity mechanics in games like “Super Mario Galaxy”, where Mario can walk on spherical planetoids and the gravity always pulls him towards the center of the planet.

There are a few things you’ll need to address:

  1. Gravity Direction: Ensure your gravity direction is normalized, meaning it’s a unit vector. This ensures that you’re only changing the direction of gravity, not its magnitude. Modify your CalculateGravityDirection function:

cppCopy code

FVector ASpaceGravityCharacter::CalculateGravityDirection() { return (CurrentPlanet->GetActorLocation() - GetActorLocation()).GetSafeNormal(); }
  1. Orientation: Your character’s orientation (or “up” direction) should be opposite to the gravity direction. So, you’ll need a function or mechanism to smoothly rotate your character so their feet point towards the planet’s center. This is typically achieved using a lerp function or the FMath::RInterpTo function to interpolate the character’s rotation.

  2. Character Movement Component: The default UCharacterMovementComponent assumes gravity is always in the downward Z direction. It checks if the character is grounded by doing a simple downward line trace. When you change gravity’s direction, this check isn’t valid anymore. You’ll need to either modify the movement component (which can be complex and prone to issues) or derive your own custom movement component from it and override the appropriate functions.A potential starting point is the IsFalling() function. You might need to override this to take your custom gravity direction into account.

  3. Custom Physics: Given the unique gravity requirements of your game, you might need a custom physics handler. This could be achieved by setting the character to fly mode (SetMovementMode(MOVE_Flying)) and then manually applying gravity and ground checks each tick.

  4. Performance: Constantly checking gravity direction every tick for multiple actors can be performance-intensive. You might want to optimize this for larger numbers of actors or bigger worlds.

  5. Other Systems: Remember that changing gravity direction might affect other systems like jumping, climbing, etc. You’ll need to account for these in your custom movement component.

Your concept is an exciting and unique challenge that will require diving deep into Unreal’s movement and physics systems. While complex, it’s definitely doable with careful planning and testing.

Close, but worse.

The movement component restricts the angle of a slope you can walk on based on Z Up / regualr gravity.

You can try to open up that angle to allow upsidedown movement as well, but it would really be more practical to write your own movement component for this.

Also, fwiw…
Pray - the original one from 2006 - was the first game (which I remeber and am sure of?) that changed gravity on the go.
It was also the first game with Portals, though you couldnt shoot them like in Valv’s innovation.
The later iteration of the same title which Bethesda (who took a few hours off kicking the skyrim dead horse) published (developed by arkane studios) also had some innovative - or cool anyway - local gravitity changes.
Retaining the round planetoid gimmick first introduced by the homonymous title’s predecessor.

This to say, since 2006 theres a bunch of plugins - some more reliable than others - avaliable in marketplace that do exactly this…

Thanks, this was exactly the kind of advice i was looking for, you gave me an idea on how to move on with this.