Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jitter when CharacterVirtual is standing on a diagonally downwards moving platform #1514

Open
Ono-Sendai opened this issue Feb 16, 2025 · 7 comments

Comments

@Ono-Sendai
Copy link
Contributor

Hi Jorrit, there's an issue when a CharacterVirtual is standing on a platform that is moving downwards but also sideways. See the following video:

jolt.diagonal.platform.jitter.mp4

Note that everything works fine as the platform moves up, but when moving down the avatar jitters sideways relative to the ground.

Patch to repro is to change line 630 of Samples\Tests\Character\CharacterBaseTest.cpp
to

mBodyInterface->MoveKinematic(mReversingVerticallyMovingBody, pos + Vec3(0, mReversingVerticallyMovingVelocity * 1.0f * inParams.mDeltaTime, mReversingVerticallyMovingVelocity * inParams.mDeltaTime), cReversingVerticallyMovingOrientation, inParams.mDeltaTime);

Cheers,
Nick

@jrouwe
Copy link
Owner

jrouwe commented Feb 16, 2025

It is caused by PhysicsSystem::Update and CharacterVirtual::Update being called at different times. The physics update will move the platform away from the character. This means that at the beginning of the character update the world state is:

Image

The red line indicates the platform velocity, which is what the character will inherit:

Vec3 ground_velocity = mCharacter->GetGroundVelocity();

It will currently, unconditionally, add gravity to that velocity (green):

new_velocity += (character_up_rotation * mPhysicsSystem->GetGravity()) * inDeltaTime;

So the resulting velocity will be the blue arrow. This means that the character will hit the platform slightly to the right of where it used to be standing and shift a little bit to the right.

I can fix this particular case by moving the gravity calculation in the else clause like this:

if (...)
{
	// Assume velocity of ground when on ground
	new_velocity = ground_velocity;

	// Jump
	if (inJump && moving_towards_ground)
		new_velocity += sJumpSpeed * mCharacter->GetUp();
}
else
{
	new_velocity = current_vertical_velocity;

	// Gravity
	new_velocity += (character_up_rotation * mPhysicsSystem->GetGravity()) * inDeltaTime;
}

which has the disadvantage that it takes 1 frame longer before gravity will kick in after the platform changes direction. This will make the scene look like this:

2025-02-16.20-26-32.mp4

You can probably add some extra logic to detect platform velocity changes to get rid of the hops, but I really consider this 'game code' as everybody can make their own choices how this should behave.

@Ono-Sendai
Copy link
Contributor Author

Thanks for the reply. Will try it out soon.

@Ono-Sendai
Copy link
Contributor Author

Unfortunately that approach has its own problems - the character becoming unsupported from the ground in some situations on moving (and rotating) platforms.

@jrouwe
Copy link
Owner

jrouwe commented Feb 21, 2025

Are you using the 'stick to floor' feature?

@Ono-Sendai
Copy link
Contributor Author

yeah

@jrouwe
Copy link
Owner

jrouwe commented Feb 23, 2025

Are you able to create a repro in the Samples app? The mRotatingAndTranslatingBody body in the samples moves and rotates at the same time and doesn't seem to have issues.

@Ono-Sendai
Copy link
Contributor Author

Here's an example of problems when gravity is only applied with character is not supported:
https://youtu.be/UCLnK43sRJA

It seems like something to do with interacting with complicated mesh geometry. I don't really want to try and make a repro in the samples app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants