Character is glitching when moving for other clients (when not moving fully fowards)

So the problem is in fact the code, and not the loop? Since for the client looks normal because it is doing it directly on the client and there is no waiting, which explains why for the other clients it looks glitchy and for the server, and why using HeartBeat makes it glitchy for the client itself aswell

In other words, you probably want to re-code your script in a more efficient way that brings the same results, I could maybe try to help you with that if you showed me footage of the character turning and how it interactcs

1 Like

It’s properly doing it with renderstepped on the client that runs the loop…
→ if I change the loop to stepped, it also becomes glitchy on the client that runs the loop, which indicates that the loop itself is the issue, no?

1 Like

Oh yea :sweat_smile:, I confused RunStepped with Stepped, sorry about that!

2 Likes

You know that moving your character by setting the character’s CFrame is a teleport as far as the physics engine is concerned, not smooth movement, right?

Roblox avatars normally move around using the Humanoid:MoveTo() function and setting their move direction (which is actually a velocity) and this ensures that their movement is interpolated on the server and all other clients. If you just CFrame them, the server and client will only get updates about every 3 render frames (~20 FPS), and the timing won’t be smooth, it will just update whenever each client gets and processes the replicated CFrame packet. Irregularity of travel time of the packets across the internet, and any additional delays sending, receiving, and processing the packet will all be visible in the movement of the character. In other words, the relative timing of position changes on the originating client is not preserved on the server or any other client.

2 Likes

How would I change the rotation of the humanoidrootpart without causing replication issues?
I mean this camera script method is quite common.

1 Like

Trigonometry? If I remember right there is a way to turn a part to look at something with orientation only, but I will check that

The Humanoid has some built in code to handle this, which is affected by a few things like Humanoid.AutoRotate, UserGameSettings.RotateType, and Humanoid:Move()'s second parameter, the cameraRelativeMovement bool. In first person and shift lock, the character rotates with the camera because it’s using AutoRotate and setting the move direction to be the camera direction. The newer ControllerManager system has move direction and facing direction separately exposed to make this easier to control.

If you want to roll your own system for a character with no humanoid, you can achieve similar with an AlignOrientation constraint or the older BodyGyro. Both of these still only replicated changes at 20 FPS, but they are smoothly interpolated towards the current value everywhere, so the results aren’t jerky.

Generally, you should not directly set the CFrame of a character model every frame, you should only do this if you’re actually trying to teleport the character or instantly snap them to a position and orientation once. This applies also to using PivotTo().

2 Likes

I’m not understanding what the solution would be in practice.
The idea is to accomplish this with a replication friendly method.

"hrp" = CFrame.new(targetPart.Position) * CFrame.Angles(0, math.rad(cameraRotationY), 0))

What would be your suggestion and way to implement it?
The only thing I kind of understand is the AlignOrientation. By changing the CFrame through the attatchment it is rendered differently?

Yes. If instead of setting HRP.CFrame directly you set the control attachment of an AlignOrientation, or equivalently a BodyGyro.CFrame of a BodyGyro parented to the HRP (this is an older, deprecated way but it still works), then the resulting movement of the character is interpolated on all clients. Depending on the settings of the constraint, it can be pretty snappy (e.g. with RigidityEnabled) or it can be slower and feel like it’s lagging behind input a bit, but it will be smooth.

2 Likes

You’re trying to rotate the the humanoid towards the camera while they are moving in another direction, when Roblox humanoids automatically turn towards the direction of their walking.

3 Likes

oh… how do I prevent the humanoid from turning the HRP?

1 Like

There is a option to that on the humanoid itself called “AutoRotate”

1 Like

I am testing how AlignOrientation too works btw, but yeah the glitching was caused by the autorotate bool being turned on. Now I know this property exists :sweat_smile: .

1 Like

Ah, yes, IIRC the built-in Humanoid gyros are effectively infinite torque, so if you have AutoRotate on, it’s going to fight against attempts to manually orient the character in a different direction, the same way the the regular upright gyro thwarts attempts to tilt the character when in the Running state.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.