I’m having an issue with crouching. The code works well for the clients, but when the server crouches, the character keeps moving up and down (shown in the video bellow).
Down bellow is also a print of my crouching code.
Does anyone have any idea why this is happening?
I tried using the Crouch and UnCrouch functions, but the problem persist.
Perhaps the issue is with the fact that you are updating capsule halfheight only on client (there is no capsule halfheight update inside rpc). Because of this there appears a mismatch between server and client positions of the character, and since the server is authorative on the movement it constantly tries to correct the client position, and it results in jittering
I changed the code (Image bellow), so the crouching also goes through the server. The jittering stopped, but characters now sink through the floor when crouching (image from previous update).
There’s still a replication issue, I think. Because before, at least, it was working for the client.
I suppose it’s actually due to the fact that when you change the capsule size it shrinks to the “center” of your character, and the root of your character mesh is on the floor (and does not move with the capsule shrink). That results in the mesh sticking out from the capsule, and since it’s the capsule that is responsible for collision with the floor, character’s legs get under the floor.
So you should move the mesh location upwards together with changing the capsule size.
But actually, I would strongly suggest you to use unreal implementation for crouching, you can go a long way with it. Just call server (called from owning client, executed on server) RPCs on your input to Crouch/Uncrouch, engine code will replicate it to other clients by itself. With correct setup it should work perfectly fine for you