CFrame not replicating while character is anchored

What I’m doing:

  • Anchor humanoid root part
  • CFrame (lerping) from one point to another
  • Unanchor at the end

On client:

  • Character smoothly tweens from one point to the other

On other clients:

  • Character freezes then teleports after it’s unanchored to the goal point

Is there any way to replicate the character’s CFrame while lerping?

2 Likes

How you tried calling the NPC’s Primary Part’s PrimaryPart:SetNetworkOwner() method and setting the value to nil?

It’s not an NPC, it’s the player’s character.

I can reproduce this by anchoring the HumanoidRootPart running a tween on it from a LocalScript. I believe this is happening because by anchoring the root part locally, physically it becomes out of sync with the server and replication stops working.

On the client if you anchor the root part, move the character, then switch to the server, you’ll see similar behavior.

Is it possible for you to run this lerp / tween on the server instead of on the client?

Here’s the answer:

Ive run into this problem myself and have therefore discovered what’s causing it. There is a thing called network ownership that every basepart have. Who the network owner is decides who will do the physics calculations. By default the network owner of the character is the client that controls the character. This is why teleportation and speed hacks is a problem.

So why would we even give the client network ownership over there character? The simple answer is that we avoid the delay and the character movement will appear much smoother and responsive for the client controlling the character.

By anchoring a basepart you take away the need to do physics calculations, cause the part is no longer affected by physics. So when you anchor the character you take away the clients ability to manipulate character movement, because the client no longer have network ownership over their character.

Setting the walkspeed to 0 should take away the characters ability to move besides falling. You could also set the jump power to 0. Another method would be to use bodymovers.

1 Like

I need the root to be anchored because I don’t want gravity affecting the character.

Have you considered just a max-force BodyPosition on the HumanoidRootPart rather than anchoring? Likewise, you can use a BodyGyro to force an orientation. AlignPosition and AlignOrientation can be used also. You’d tween the BodyMover properties rather than set CFrames of the HRP.

1 Like

This is still an issue, I can’t use body movers because of gravity and because I’m putting the character inside collide-able parts which doesn’t work with body movers since they’re based on physics. I’ve also tried using align position but it didn’t work either.

Try doing something like this:

  1. Anchor the player from their LocalScript
  2. Fire a remote to the server script
  3. Start changing their position from their LocalScript
  4. The server script tells all other clients to move your character aswell
  5. The character is moved on everybody’s screen :smiley:
  6. Unanchor the character and everything’s back to normal

Basically client-sided positioning I guess? This is what most games do i.e. with bullets, pets (simulators), etc.

Body movers can all counteract gravity, no problem there.

If you want smooth client-side movement seen by everyone, you have to leverage the physics system’s built-in interpolation, which means using BodyMovers or constraints. There are a lot of constraint options you can use to smoothing slide something along a line segment, not just bodymovers but things like prismatic constraint. Any part you CFrame-position on the server is going to update on the client at the replication rate, a potentially-erratic ~20fps. The only other way to get it smooth on the client is an option so terrible I’m not even going to suggest it.

Collision groups can solve the issue of wanting player characters to overlap physically-simulated parts. Just make the parts of the character not able to collide with things during the move. You can also put the character into the Physics HumanoidState and manually set all body and accessory parts to CanCollide=false. Collision Groups is the better option.

Okay, I had the exact same issue and I’ve made it work.

First of all, Roblox will not replicate client-owned parts that are anchored.

So you have to Unanchor the part.

Then once its unanchored, you have all sorts of other issues to deal with like gravity, rotation, velocity, etc.

You can counteract all of that with something like the following:

if (DoUnAnchoredPhysics ==true) then
    	local BodyForce = playerModel:FindFirstChild("BodyForce",true)
    	BodyForce.Force = Vector3.new(0, playerModel.PrimaryPart:GetMass() * workspace.Gravity,0) --If you have more than 1 part, you'll have to calculate the mass total..
    	playerModel.PrimaryPart.Velocity = Vector3.new(0,0,0)
    	playerModel.PrimaryPart.Orientation = Vector3.new(0,0,0)
    	playerModel.PrimaryPart.RotVelocity = Vector3.new(0,0,0)
end

Then you are free to just set the parts position every frame however you want, and it will replicate as expected.

14 Likes