Hi, physic predictions are working quite nice, especially with impulses and dynamic physic bodies. I can get it to work with PhysicsVelocity.ApplyLinearImpulse() before BuildPhysicWorld, but what I wonder is, is it also possible to use physic preditions with PhysicsWorld.ApplyImpulse() (working on physic simulation data, instead of ECS components)?
I get the error “To guarantee safety, you must include Broadphase: prepareStaticBodyDataJob as a dependency of the newly scheduled job.” when doing this
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateAfter(typeof(BuildPhysicsWorld))]
[UpdateBefore(typeof(StepPhysicsWorld))]
public partial class PredictionSwitchingApplyInputSystem : SystemBase
{
private GhostPredictionSystemGroup m_GhostPredictionSystemGroup;
private BuildPhysicsWorld buildPhysicsWorld;
protected override void OnCreate()
{
base.OnCreate();
RequireSingletonForUpdate<PredictionSwitchingSpawner>();
m_GhostPredictionSystemGroup = World.GetExistingSystem<GhostPredictionSystemGroup>();
buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
}
protected override void OnStartRunning() {
base.OnStartRunning();
buildPhysicsWorld.RegisterPhysicsRuntimeSystemReadWrite();
}
protected override void OnUpdate()
{
var tick = m_GhostPredictionSystemGroup.PredictingTick;
PhysicsWorld world = this.buildPhysicsWorld.PhysicsWorld;
Dependency = Entities
.ForEach(
(
Entity entity,
DynamicBuffer<PredictionSwitchingInput> inputBuffer,
in Translation translation,
in PredictedGhostComponent prediction
) => {
if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) {
return;
}
inputBuffer.GetDataAtTick(tick, out PredictionSwitchingInput input);
float3 impulse = new float3();
if (input.horizontal > 0)
impulse = new float3(10, 0, 0);
if (input.horizontal < 0)
impulse = new float3(-10, 0, 0);
if (input.vertical > 0)
impulse = new float3(0, 0, 10);
if (input.vertical < 0)
impulse = new float3(0, 0, -10);
int ceIdx = world.GetRigidBodyIndex(entity);
world.ApplyImpulse(ceIdx, impulse, translation.Value);
}
).Schedule(Dependency);
}
}