I am trying to setup my project to have physics on the server and have the clients interpolate. Before I was having issues with my project I, the frame rate was fine. Now that I have recreated it, I am seeing an average of 20 FPS.
I saw this post here: Physics + Netcode not syncing right or something
I tried what was suggested, but I am still getting low frames. There is a lot of GC going on, that frankly, I don’t understand why.
This is running on the server side:
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var group = World.GetExistingSystem<GhostPredictionSystemGroup>();
var tick = group.PredictingTick;
var deltaTime = Time.DeltaTime;
var inputData = default(PlayerInput);
var job = Entities.ForEach((DynamicBuffer<PlayerInput> inputBuffer, ref Translation translation, ref Rotation rotation, ref CharacterControllerData characterData,
ref PhysicsVelocity velocity, ref PredictedGhostComponent prediction) => {
if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
return;
inputBuffer.GetDataAtTick(tick, out inputData);
var jump = inputData.jump == PlayerInput.Jumped;
float3 Up = new float3(0f, 1f, 0f);
var moveDirection = float3.zero;
var haveMovement = inputData.forward != 0 || inputData.back != 0 || inputData.left != 0 || inputData.right != 0;
//Movement
if (haveMovement) {
characterData.IsJumping = jump && characterData.IsSupported;
if (inputData.forward != 0) {
moveDirection = new float3(0, 0, 1);
}
if (inputData.back != 0) {
moveDirection += new float3(0, 0, -1);
}
if (inputData.left != 0) {
moveDirection += new float3(-1, 0, 0);
}
if (inputData.right != 0) {
moveDirection += new float3(1, 0, 0);
}
characterData.MovementVector = math.normalize(moveDirection);
}
//rotation
var haveRotation = inputData.shootX != 0 || inputData.shootY != 0;
if (haveRotation) {
var rotSpeed = characterData.RotationSpeed * deltaTime;
var shootRotation = quaternion.LookRotation(new float3(inputData.shootX, 0, inputData.shootY), Up);
characterData.Rotation = math.slerp(characterData.Rotation, shootRotation, rotSpeed);
}
else if (!characterData.gamePadConnected) {
characterData.MousePosition.y = translation.Value.y;
var direction = math.normalize(characterData.MousePosition - translation.Value);
characterData.Rotation = quaternion.LookRotation(direction, Up);
}
//Tweek Velocity
float3 linearVelocity = velocity.Linear;
linearVelocity *= characterData.MovementDamping;
bool isMoving = characterData.IsJumping || (math.lengthsq(characterData.MovementVector) > (characterData.DeadZone * characterData.DeadZone));
if (isMoving) {
var y = linearVelocity.y;
if (characterData.IsSupported) {
linearVelocity = characterData.MovementSpeed * characterData.MovementVector;
linearVelocity.y = y;
if (characterData.IsJumping) {
linearVelocity.y += characterData.JumpSpeed;
characterData.IsJumping = false;
}
}
else {
characterData.InitialUnsupportedVelocity *= characterData.MovementDamping;
characterData.InitialUnsupportedVelocity.y = y;
linearVelocity = characterData.InitialUnsupportedVelocity + (characterData.MovementSpeedInAir * characterData.MovementVector);
}
}
velocity.Linear = linearVelocity;
velocity.Angular = float3.zero;
rotation.Value = characterData.Rotation;
}).Schedule(inputDependencies);
return job;
}
