Using DOTS Physics v0.5
I have a InputResponse system that takes WASD and updates the PhysicsVelocity of my player entity.
Entities
.WithReadOnly(inputFromEntity)
.WithReadOnly(childFromEntity)
.WithReadOnly(localToWorldFromEntity)
.WithAll<PlayerTag, PlayerCommand, Child>()
.ForEach((Entity entity, int nativeThreadIndex, ref Translation position, ref Rotation rotation,
ref PhysicsVelocity physicsVelocity, ref PlayerStateComponent state,
in GhostOwnerComponent ghostOwner, in PredictedGhostComponent prediction) =>
{
if (!GhostPredictionSystemGroup.ShouldPredict(currentTick, prediction))
return;
var input = inputFromEntity[entity];
PlayerCommand inputData;
if (!input.GetDataAtTick(currentTick, out inputData))
inputData.shoot = 0;
state.State = inputData.thrust;
var linearVelocity = physicsVelocity.Linear.xyz;
var amount = 50;
if (inputData.right == 1)
{ //thrust to the right of where the player is facing
linearVelocity -= math.mul(rotation.Value, new float3(-1,0,0)).xyz * deltaTime * amount;
}
if (inputData.left == 1)
{ //thrust to the left of where the player is facing
linearVelocity -= math.mul(rotation.Value, new float3(1,0,0)).xyz * deltaTime * amount;
}
if (inputData.thrust == 1)
{ //thrust forward of where the player is facing
linearVelocity += math.mul(rotation.Value, new float3(0,0,1)).xyz * deltaTime * amount;
}
if (inputData.reverseThrust == 1)
{ //thrust backwards of where the player is facing
linearVelocity += math.mul(rotation.Value, new float3(0,0,-1)).xyz * deltaTime * amount;
}
linearVelocity.x = ((int)(linearVelocity.x * 100.0f))/100.0f;
linearVelocity.y = ((int)(linearVelocity.y * 100.0f))/100.0f;
linearVelocity.z = ((int)(linearVelocity.z * 100.0f))/100.0f;
physicsVelocity.Linear.xyz = linearVelocity;
This results in this odd jittery effect:
I had initially thought this had something to networking but finally pinpointed the issue. The PhysicsVelocity.Linear randomly drops from its value down, and then returns to its normal value.
I printed the PhysicsVelocity.Linear for both Server/Client (to make sure the issue wasn’t a discrepancy)
[
There was no change in thrust in between those logs.
Is this a known DOTS Physics issue because we are using preview packages or is it something else?
I also updated to use Linear Impulses and still got the same jittery effect and change in PhysicsVelocity.Linear
if (inputData.right == 1)
{ //thrust to the right of where the player is facing
// linearVelocity += math.mul(rotation.Value, new float3(1,0,0)).xyz * deltaTime * amount;
PhysicsComponentExtensions.ApplyLinearImpulse(ref physicsVelocity, physicsMass, (math.mul(rotation.Value, new float3(1,0,0)).xyz));
}
if (inputData.left == 1)
{ //thrust to the left of where the player is facing
// linearVelocity += math.mul(rotation.Value, new float3(-1,0,0)).xyz * deltaTime * amount;
PhysicsComponentExtensions.ApplyLinearImpulse(ref physicsVelocity, physicsMass, (math.mul(rotation.Value, new float3(-1,0,0)).xyz));
}
if (inputData.thrust == 1)
{ //thrust forward of where the player is facing
// linearVelocity += math.mul(rotation.Value, new float3(0,0,1)).xyz * deltaTime * amount;
PhysicsComponentExtensions.ApplyLinearImpulse(ref physicsVelocity, physicsMass, (math.mul(rotation.Value, new float3(0,0,1)).xyz));
}
if (inputData.reverseThrust == 1)
{ //thrust backwards of where the player is facing
// linearVelocity += math.mul(rotation.Value, new float3(0,0,-1)).xyz * deltaTime * amount;
PhysicsComponentExtensions.ApplyLinearImpulse(ref physicsVelocity, physicsMass, (math.mul(rotation.Value, new float3(0,0,-1)).xyz));
}