I have this struct
{
public Vector2 move;
public Vector2 look;
public InputEvent jump;
public quaternion lookRotation;
}
A system then fills in the struct:
foreach (RefRW<PlayerInputData> input in SystemAPI.Query<RefRW<PlayerInputData>>().WithAll<GhostOwnerIsLocal>())
{
input.ValueRW.look = new UnityEngine.Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
}
I then finally apply the inputs, with client prediction on. This works, all clients can see each others avatars rotating, but there is jitter, (i assume it’s from the prediction).
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
partial class CameraControlSystem : SystemBase
{
protected override void OnUpdate()
{
foreach (var (localTransform, cameraControl, playerInputData) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<CameraControl>, RefRO<PlayerInputData>>())
{
localTransform.ValueRW = localTransform.ValueRW.RotateX(-playerInputData.ValueRO.look.y * cameraControl.ValueRO.rotateSpeed);
var worldYrotation = quaternion.AxisAngle(new float3(0, 1, 0), playerInputData.ValueRO.look.x * cameraControl.ValueRO.rotateSpeed);
localTransform.ValueRW.Rotation = math.mul(worldYrotation, localTransform.ValueRO.Rotation);
{
...
Instead of sending the mouse input over to the server I though I might try letting the client hold the rotation as a quaternion and send that over instead (to see if it helps reduce jitter)
So here i calc the quaternion and store it in the IInputComponentData
foreach (RefRW<PlayerInputData> input in SystemAPI.Query<RefRW<PlayerInputData>>().WithAll<GhostOwnerIsLocal>())
{
input.ValueRW.lookRotation = math.mul(input.ValueRO.lookRotation, quaternion.AxisAngle(new float3(1, 0, 0), -Input.GetAxis("Mouse Y") * 0.05f));
input.ValueRW.lookRotation = math.mul(quaternion.AxisAngle(new float3(0, 1, 0), Input.GetAxis("Mouse X") * 0.05f), input.ValueRO.lookRotation);
}
and finally apply that quaternion:
partial class CameraControlSystem : SystemBase
{
protected override void OnUpdate()
{
foreach (var (localTransform, cameraControl, playerInputData) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<CameraControl>, RefRO<PlayerInputData>>())
{
localTransform.ValueRW.Rotation = playerInputData.ValueRO.lookRotation;
{
...
Now each client can rotate their own camera around without jitter, yay, but the other clients can’t anybody else rotation.
I have no clue why this is happening, I assumed that anything inside of IInputComponentData will work with prediction