For some reason my game slows down like this when I schedule this job.
[BurstCompile] private struct MovementJob : IJobForEachWithEntity<PathIndex , PlatoonReference , Translation>
{
[ReadOnly] public float dt;
[ReadOnly] public BufferFromEntity<PathPosition> pathPositionBufferFromEntity;
public void Execute( Entity entity , int index , ref PathIndex pathIndex , ref PlatoonReference reference , ref Translation translation )
{
if ( pathIndex.value >= 0 )
{
DynamicBuffer<PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[ reference.entity ];
float3 pathPosition = new float3(
pathPositionBuffer[ pathIndex.value ].position.x ,
translation.Value.y ,
pathPositionBuffer[ pathIndex.value ].position.y );
float distance = math.distance(
pathPosition , translation.Value );
float3 direction = math.normalize(
pathPosition - translation.Value );
int branch = math.select( 0 , 1 , math.abs( direction.x ) <= 1 );
float3 value = new float3(
direction.x * 30f * dt ,
0 ,
direction.z * 30f * dt );
translation.Value += value * branch;
branch = math.select( 0 , 1 , distance <= 0.3f );
pathIndex.value -= branch;
}
}
}