Hi there!
Recently I’ve been doing some testing regarding faking centrifugal gravity in UE4 and have run into a couple of hiccups. While it was relatively easy to get basic gravity multi-directional by overriding the world’s gravity to 0 and applying impulses to objects based on the position of a point, I’ve managed to hit a wall when it comes to the character.
Getting “gravity” applied to the character works perfectly fine so far, but getting them to orient to the point correctly is not. Here is the function I’m using to do some simple gravity simulation. This is also called from Blueprint each tick and is passed a vector (the location where objects repel from).
Here are some vines to show it in action Vine and Vine
I’ve omitted some of the gravity code and pasted the orientation code here. As you can see the orientation code also prevents me from looking around vertically, so any help with that would be greatly appreciated too.
FVector DirectionalVector;
FRotator CharacterDirection;
ASpaceGameCharacter* SpaceGameCharacter = Cast<ASpaceGameCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn());
if (SpaceGameCharacter != NULL)
{
DirectionalVector = PointLocation - SpaceGameCharacter->GetActorLocation();
DirectionalVector = DirectionalVector / FMath::Sqrt(DirectionalVector.X * DirectionalVector.X + DirectionalVector.Y * DirectionalVector.Y + DirectionalVector.Z * DirectionalVector.Z);
DirectionalVector.X = 0;
CharacterDirection = DirectionalVector.Rotation();
CharacterDirection.Pitch = CharacterDirection.Pitch - 90;
CharacterDirection.Roll = SpaceGameCharacter->GetController()->GetControlRotation().Roll;
CharacterDirection.Yaw = SpaceGameCharacter->GetController()->GetControlRotation().Yaw;
SpaceGameCharacter->GetController()->SetControlRotation(CharacterDirection);
SpaceGameCharacter->GetCapsuleComponent()->SetWorldRotation(CharacterDirection);
}
So far the character orients fairly well, but only if I’m facing the right direction as shown here. The orientation only seems to be correct if I’m facing a certain way. This has also been prototype’d out with Blueprint by traces and using the hit location normal to the same (albeit less smooth) results, it only acts as though I’m oriented correctly if I’m facing a certain way.
So basically any help, ideas, or pointing in the right direction for this problem would be greatly appreciated. In the long run I intend to try and have the character able to walk around and orient themselves correctly in a cylinder type environment