My character controller retrieves the X-axis value from an input action (InputAction) linked to mouse movement (MouseDelta) and uses it to rotate the character model. As shown in the video below, vertical movement (the Y-axis, or pitch) is very smooth. Unfortunately, this is not the case for horizontal rotation (the X-axis, or yaw).
I call this function within the BindToSimulation callback at a rate of 60 Hz:
function _apply_yaw(self: types.motion_obj, look_yaw_delta: number, dt: number, loco_mode: number)
local max_delta = math.pi * 2 * dt -- TODO
local clamped_delta = clamp(
look_yaw_delta * dt * .002,
-max_delta,
max_delta
)
if clamped_delta == 0 then
return
end
set_yaw_kinematic(self, get_current_yaw(self) - clamped_delta)
end
As you can see, rotating the camera up and down is smooth, whereas movement to the left and right is extremely jittery:
i just fire unreliable remote when doing character rotation
Its not really ideal and i will probably reconsider that but that what i do
You seem to be writing first person camera controller so you may be interested with this:
I, personally, would just linearly interpolate that value. It will effectively smooth it out, and its really common in most games to use Linear interpolation in order to smooth networking stuff out.
local PreviousYaw = 0
local YawWeight = 0.5
function _apply_yaw(self: types.motion_obj, look_yaw_delta: number, dt: number, loco_mode: number)
local max_delta = math.pi * 2 * dt -- TODO
local clamped_delta = clamp(
look_yaw_delta * dt * .002,
-max_delta,
max_delta
)
smoothed_delta = math.lerp(PreviousYaw, clamped_delta, YawWeight)
if clamped_delta == 0 then
return
end
set_yaw_kinematic(self, get_current_yaw(self) - smoothed_delta)
PreviousYaw = clamped_delta
end
Also, Unreliable would be good for this. However! Be noted that you need to fire that at an increased frequency because Roblox will in fact drop most of those packets when increases in CPU usage arises, and it will stutter because of that. Also the interpolation could cause a bit of weird artifacts when rotating very fast, since it naturally acts as a high frequency filter, in that case you will need to do the following:
Update other users via the authoritive model. Owning Client predicts authoritive model and does not experience that artifact.