Character Movement/Physics flickering

Hey guys, Im doing character movement on my server, and I see that is flickering some times, dno why. Im using 60fps update on client and 30fps on server (physicsworld).

Video showing the problem:
https://puu.sh/zBdGu/2826b16857.mp4

Node Settings:

Map Floor settings:

	Node * pMapNode = pScene->CreateChild( pMap->GetName(), LOCAL );
	pMapNode->SetPosition( Vector3( 0, 0, 0 ) );
	pMapNode->SetScale( Vector3( 1.0f, 1.0f, 1.0f ) );
	
	auto * pBody = pMapNode->CreateComponent<RigidBody>();
	pBody->SetFriction( 1.0f );

	auto * pShape = pMapNode->CreateComponent<CollisionShape>();
	pShape->SetTriangleMesh( GetSubsystem<ResourceCache>()->GetResource<Model>( 	pMap->GetBaseMap()->GetFileName() ) );

Character Mover on Server:

	Node * pCharacterNode = GetNode();
	auto * pCharacterBody = pCharacterNode->GetComponent<RigidBody>();
	
	const Controls & cControls = pConnection->GetControls();
	const Vector3 & cVelocity = pCharacterBody->GetLinearVelocity();
	
	Quaternion cRotation( 0.0f, cControls.yaw_, 0.0f );
	Vector3 cMoveDirection = Vector3::ZERO;

	Vector3 cPlaneVelocity( cVelocity.x_, 0.0f, cVelocity.z_ );

	if( cControls.buttons_ & CHARACTERCONTROL_Forward )
	{
		cMoveDirection += Vector3::FORWARD;
		pCharacterNode->SetRotation( cRotation );
	}
	
	if( cMoveDirection.LengthSquared() > 0.0f )
		cMoveDirection.Normalize();

	pCharacterBody->ApplyImpulse( cRotation * cMoveDirection * 1.0f );

	Vector3 cBrakeForce = -cPlaneVelocity * 0.1f;
	pCharacterBody->ApplyImpulse( cBrakeForce );

Thanks!

Does it work smoothly if simulated locally?

Server is running locally, so, shouldnt happen this. Dont know if can be some setting on physics… I tried get the physics settings from 18_CharacterDemo sample.

node->GetOrCreateComponent<SmoothedTransform>();
1 Like

I think the below code affecting that motion.

Vector3 cBrakeForce = -cPlaneVelocity * 0.1f;
pCharacterBody->ApplyImpulse( cBrakeForce );

Can you comment it out to see if it is ok?

Do you work with physics in function FixedUpdate() ?

Yes, Im using a Logic Component. ll try about SmoothedTransform.

Didnt work.

@ Could be something on yaw? Dno. Nothing works until now.

//Manipulating Camera Yaw
if( INPUT->GetKeyDown( KEY_LEFT ) )
	fCameraYaw += 0.5f;
else if( INPUT->GetKeyDown( KEY_RIGHT ) )
	fCameraYaw -= 0.5f;

//Getting Mouse Yaw
fMouseYaw = Atan2( INPUT->GetMousePosition().y_ - (GRAPHICS->GetSize().y_ >> 1), INPUT->GetMousePosition().x_ - (GRAPHICS->GetSize().x_ >> 1) ) + 90.0f;

And to send to server side:

cControls.yaw_ = CAMERAMANAGER->GetCameraYaw() + CAMERAMANAGER->GetMouseYaw();

@@ 've tried remove brake force, change the value that Im multiplying the impulse, but nothing is changed. Same problem on all changes.

@@@ Same making the physics on PhysicsPreStep…

pCharacterNode->SetRotation( cRotation );

actually you can not set rotations and positions for dynamics bodies, you can use only forces and impulses

Honestly, you do not need to rotate the capsule, just push it in the direction you want. Just rotate camera around object in Update (in Update you can use standart input->GetMouseMove() for yaw)

You can calculate impulses which will move the body.
For example I use this code for control movement speed:

        Vector3 desiredVel = rotation * dir * MOVE_SPEED;
        Vector3 impulse = (desiredVel - playerBody->GetLinearVelocity()) * playerBody->GetMass();// * 0.1f;
        playerBody->ApplyImpulse(impulse);

Same for rotations

EDIT: based on http://www.iforce2d.net/b2dtut/constant-speed

Hmm ic. Same after all changes quoted on this topic, the problem always appears, dno why.

If I use ur code out this condition if( cControls.buttons_ & CHARACTERCONTROL_Forward ), this happens (beyond flickr)

Its strange, in every way the flicker happens lol.

Could you provide a repository that we could look at? This seems like an issue that could encompass many parts of the code, and providing the full scope could help. Also I want to say, your graphical style is really slick.

+1 for @Don
I could investigate the problem if there is something run-able.

Haa, I have an idea.

Ensure that:

  1. You have turned off server physics interpolation.
  2. You have RigidBody of your character only on server side. The code may work even if you have bodies both on client and server side. I’d like not to tempt fate.

Position and rotation are Node attributes, while linear and angular velocities are RigidBody attributes. To cut down on the needed network bandwidth the physics components can be created as local on the server: in this case the client will not see them at all, and will only interpolate motion based on the node’s transform changes. Replicating the actual physics components allows the client to extrapolate using its own physics simulation, and to also perform collision detection, though always non-authoritatively.

By default the physics simulation also performs interpolation to enable smooth motion when the rendering framerate is higher than the physics FPS. This should be disabled on the server scene to ensure that the clients do not receive interpolated and therefore possibly non-physical positions and rotations. See SetInterpolation().

1 Like

Hmm ye I have character only on server side… I should create in client replicated or local? I will not have 2 characters at same time?

Thanks for ur help, I believe that u solved the problem, ll try this later.

If you have character on the server side only, it should be fine.
Then, just turn off physics interpolation on the server side.
If it doen’t help… well, make a sample for ppl to try it. I’ve never seen such bugs with sample network app.

Interpolation was already turned off lol.

SVN Repo:
client: https://subversion.assembla.com/svn/dev-client/trunk
server: https://subversion.assembla.com/svn/dev-server/trunk
shared: https://subversion.assembla.com/svn/dev-shared/trunk

If someone want to see this in-game: https://puu.sh/zCy4x/f004273bf4.rar
(should run login server, after game server)(can type any login and pw, and dont need a character nick)(to walk let mouse button left pressing or double click with mouse button left)

void CMapHandler::CreateScene() - create scene to server and maps collision
CCharacter * CCharacterHandler::LoadCharacter( Connection * pConnection, String strCharacterName ) - instantie XML responsible for character node and create the logic component CCharacter
void CCharacter::FixedUpdate( float fTime ) - physics of each character at scene

I really dno what more can be, Im “newbie” on Urho3D, and until now this is the unique problem I dont solved.
Thanks.

Archive seems broken. Or maybe some very new version of winRAR.
Tried to download&open it two times.

And… I have no idea how to download SVN repos w/o any installed SVN client.

1 Like

I’m looking at your code and I’m not sure that the Client doesn’t have RigidBody component: in the file Server Data\Objects\Character.xml there is replicated RigidBody component that is probably replicated on the client side.