Dynamic gravity for characters

…com/=RKQoEJyZbLg

How can I rotate character in air when I want?(without set gravity direction)

I found it… Disable ‘Align Component to Gravity’, then I can rotate character with things like ‘AddActorWorldRotation’.

How did you get the player camera to work like that?

Hey there, just started messing around with the codebase and I’ve been running into the some of the same issues with the Control Rotation. Fairly certain the entire control orientation flips upside down (well, definitely flips, not necessarily completely upside down) as soon as the orientation of the character passes 90 degrees off of regular World-Z.

Re: Control-Up becomes Control-Right.
Control-Right becomes Control-Down.

Edit:
I’ve gone through a couple of different iterations of directly setting the Control Rotation to have the same values as my capsule rotation in the update tick, and I am pretty convinced that it is being reset to something else after that point. It’s strange though, because I’ve tried just modifying the roll to compensate for the apparent error, offsetting the rotation by 90 degrees, but it just refuses to let the up vector for the control rotation be World down. What’s more, I can’t directly offset the roll to arbitrary values (re: 45, 37, 12, etc…) but some of the multiple-of-90 rotations DO rotate the frame (while we’re upside down), just never to the desired orientation. More experimentation to follow.

Right now the most likely culprit is the UpdateRotation call in the base PlayerController.

Edit:
Alright, figured it out (for the most part), and I was close.
It was the ProcessViewRotation call from the PlayerCameraManager in the UpdateRotation call, specifically, these:



    // PlayerCameraManager.cpp : 1124-1130
    else
    {
        // Limit Player View Axes
        LimitViewPitch( OutViewRotation, ViewPitchMin, ViewPitchMax );
        LimitViewYaw( OutViewRotation, ViewYawMin, ViewYawMax );
        LimitViewRoll( OutViewRotation, ViewRollMin, ViewRollMax );
    }

In the default player camera manager, the control rotation values for pitch, yaw, and roll are capped to -90,90], [0,360], and -90,90], respectively, and gets called every update tick. So, once I commented out these calls, I was able to directly update the control rotation to whatever I wanted. I might go back and fix it up a little better s.t. I don’t need to reassign the control rotation every tick (or just change the limits in my camera manager), but at the very least I’ve got it working for my purposes right now. It’s still pretty hacky.

Well… why not use the provided NinjaPlayerCameraManager that fixes the problem? :wink:

Hey ! Thank you for the continued support of project, work is awesome!
As to your query, I think I tried it out but decided to go with my own. I have some plans for some other things I want the camera to do.
And, uh, well, I did also run into another problem, in that while the character is inverted w/ respect to World-Z, I found that my control scheme was still inverted (re: turn camera to the left, it goes right; turn camera to the right, it goes left), and for what I’m working on I need it to remain consistent regardless of orientation.

for whoever is using 4.24, a quick fix below:

CharacterMovementComponent.h
line 1728:


virtual **void **VisualizeMovement() const;


change to:


virtual **float **VisualizeMovement() const;


NinjaCharacterMovementComponent.cpp

line 3421:


**void **UNinjaCharacterMovementComponent::VisualizeMovement() const
{
if (CharacterOwner == nullptr)
{
return;
}

change to:


**float **UNinjaCharacterMovementComponent::VisualizeMovement() const
{
if (CharacterOwner == nullptr)
{
**return 0.0f;**
}

add a return below line 3505:


#endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
**return HeightOffset;**
}

cheers
Frank

Thank you Frank, the fixes are valid and should help others work.

Hello, zaguarman how do you ask for developper group ? I cannot access the files, 404 error for me too, so can you tell me where to ask ? I would really love to get plugin and start tweaking and modifying it ! It look awesome ! Thanks a lot for sharing wonderfull work, really !

Hello, I seem to be experiencing issues when using the plugin. I’m using Unreal 4.21.2 (vanilla), and 0.9.3 of your plugin.

The seems to only occur on remote clients standing on movable objects with a rotation > 0,0,0. The problem however does not occur on the Listen server screen (each client is rotating/moving appropriately).

I wonder if I’m missing something? is a fresh project with your plugin and TP Content installed.

If it helps at all, I’m noticing that the root Actor seems to be moving appropriately; it’s only the actors skeletal mesh component that is jittering all over the place (also the transform of the skeletal mesh is showing X/Y/Z values going all over the place).

Let me know if I can provide any further information. Video below:
://www…com/=RS8-llrXz8Q

Thanks!

Hi!

Any you could update for 4.25? I’ve been trying to get it up and running for a few days now but there are a lot of errors when compiling via the "
RunUAT BuildPlugin" command.

404 error for me as well with UE connected to github

Edit: For those who have problem after me, who also have little or no github experience like me -

The “Epic Games” Team from Github will send you an invite to join the Team, will allow you access.
I believe the process is automatic, but the invite did not appear prominently for me until I followed a completely unrelated link to another UE Git repository, got the same error, then googled the team and went to Epic Games · GitHub where the invitation was in a bar at the top of the screen.

now works.

I haven’t noticed reply until now, sorry. There are issues with rotating bases in online mode, you didn’t do anything wrong, I’ll take a look for sure.

.

I have a compatible version for 4.25, but there is no ETA sorry (2020).

New version of the code plugin has been released HERE](Ninja Character - Dynamic gravity for characters & objects - Marketplace - Unreal Engine Forums), compatible with UE 4.25 and includes more features.

If you’re upgrading from plugin 0.9.3, stuff might be broken, since some names were changed.

Hi

was wondering about the new features and possible bug fixes (that multiplayer bug you mentioned before)?

Our project is using an older engine version, so contemplating to upgrade the project or not. Could you please elaborate

thank you!

Yup, I fixed the multiplayer camera bug I recorded in the video I posted, I think most of the related code went into the NinjaCharacter class.

New “hidden” features that I can remember include:

  • Added more blueprint events.
  • Added cheats to draw in-world debug information.
  • Allow capsule rotation from bottom sphere as pivot (while walking mainly) (bRotateAroundCenter).
  • Allow to keep speed magnitude when the capsule rotates (bRotateVelocity).
  • Added check for gravity direction to know if the surface is walkable when landing (bLandOnAnySurface).

But new critical multiplayer bugs were noticed after upgrading from 4.22 (moving bases broken, location desyncs), keep that in mind.
What’s the engine version you’re using?

thanks for your reply!

we’re still on .24.3

If the engine upgrade is impossible or undesired, let me know.

The only new function difference had to do with rootmotion, which we dont use

I replaced 2 if statements in movmementcomponent using bool function:

if (!HasAnimRootMotion() && !HasOverrideVelocityWithIgnoreZAccumulate())

to:

if (!HasAnimRootMotion() && !CurrentRootMotion.HasOverrideVelocity())

seems to work fine on 4.24 now, thanks!!

cheers
Frank

Hi

I had to make a local change to get smooth movement on the player for our project. Using a (quite big) spherical world seems to make the delta between old-new gravity directions too big to get a smooth transition .

Therefor I had to disable the return statement in ninjacharacter.cpp (which sets the control rotation).

Also added a rotator lerp in the movementcomponent (that still has the return statement a few lines prior).

Do you think will have a huge impact on performance eventually? If so, what would you recommend to smoothen out the (rotational)movement? Using camera lag smoothens it out a little, but not entirely (and we rather don’t have much lag on the camera)

NinjaCharacter.cpp line 223:


if ((LastAxisZ | NewAxisZ) >= THRESH_NORMALS_ARE_PARALLEL)
{
     //return;
}

NinjaCharacterMovementComponent.cpp line 5380:




// Abort if angle between new and old capsule 'up' axes almost equals to 0 degrees
if ((DesiredCapsuleUp | CurrentCapsuleUp) >= THRESH_NORMALS_ARE_PARALLEL)
{
     return;
}

//// Take desired Z rotation axis of capsule, try to keep current X rotation axis of capsule
const FRotator NewRotation = FNinjaMath::MakeFromZQuat(DesiredCapsuleUp,
UpdatedComponent->GetComponentQuat()).Rotator();
**const FRotator CurrentRotation = FNinjaMath::MakeFromZQuat(CurrentCapsuleUp,
UpdatedComponent->GetComponentQuat()).Rotator();**

if (!bRotateAroundCenter)
{
     float PawnRadius, PawnHalfHeight;
     CharacterOwner->GetCapsuleComponent()->GetScaledCapsuleSize(PawnRadius, PawnHalfHeight);

     // Rotate capsule around the origin of the bottom sphere
     const float SphereHeight = PawnHalfHeight - PawnRadius;
     const FVector Delta = CurrentCapsuleUp * (SphereHeight * -1.0f) + DesiredCapsuleUp * SphereHeight;

     **FRotator RotationLerp = UKismetMathLibrary::RInterpTo(CurrentRotation, NewRotation, GetWorld()->GetDeltaSeconds(), 4.0f);**

     // Not using MoveUpdatedComponent to bypass constraints
     UpdatedComponent->MoveComponent(Delta, **RotationLerp**, true);
}

nonetheless, nice work on the update!! Especially the new debug options are really useful!

I took the liberty to answer you HERE, let’s leave forum thread for 0.9.3 upgrade issues, please.