protected override void OnUpdate() { var tick = m_GhostPredictionSystemGroup.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, in PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } CubeInput input; inputBuffer.GetDataAtTick(tick, out input); if (input.horizontal > 0) { trans.Value.x += deltaTime; } if (input.horizontal < 0) { trans.Value.x -= deltaTime; } if (input.vertical > 0) { trans.Value.z += deltaTime; } if (input.vertical < 0) { trans.Value.z -= deltaTime; } }).ScheduleParallel(); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PredictedGhostComponent prediction, ref Rotation rot) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } CubeInput input; inputBuffer.GetDataAtTick(tick, out input); rot.Value = quaternion.AxisAngle(math.up(), input.rotation * math.PI / 180); if (input.horizontal > 0) { trans.Value.x += deltaTime; } if (input.horizontal < 0) { trans.Value.x -= deltaTime; } if (input.vertical > 0) { trans.Value.z += deltaTime; } if (input.vertical < 0) { trans.Value.z -= deltaTime; } }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; var isClient = World.GetExistingSystem <ClientSimulationSystemGroup>() != null; Entities.ForEach(( DynamicBuffer <PlayerInput> inputBuffer, ref PlayerView view, ref Rotation rot, in PlayerId playerId, in PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } PlayerInput input; inputBuffer.GetDataAtTick(tick, out input); view.pitch = input.targetPitch; view.yaw = input.targetYaw; rot.Value.value = quaternion.Euler(new float3(0, math.radians(view.yaw), 0)).value; }).ScheduleParallel();
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var predictingTick = group.PredictingTick; var deltaTime = Time.DeltaTime; var speed = _appConfig.Characters[0].Speed; var time = (int)(Time.ElapsedTime); var colliders = _colliders; var skillsMap = _skillsDurationMap; Entities.WithoutBurst().WithReadOnly(colliders).ForEach((Entity e, DynamicBuffer <PlayerInput> inputBuffer, ref Attack attack, ref Damage damage, ref Translation trans, ref PlayerData pdata, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(predictingTick, prediction)) { return; } if (!(inputBuffer.GetDataAtTick(predictingTick, out PlayerInput input) && input.Tick == predictingTick)) { // LogServer(isServer, $"Did NOT run server-side prediction because only available input had tick {input.Tick} while the predicting tick is {predictingTick}"); return; }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach(( DynamicBuffer <PlayerInput> inputBuffer, ref KCCVelocity velocity, ref KCCJumping jump, in PredictedGhostComponent prediction, in PlayerView view, in KCCMovementSettings settings) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } inputBuffer.GetDataAtTick(tick, out PlayerInput input); // Rotate movement vector around current attitude (only care about horizontal) float3 inputVector = new float3(input.horizMove, 0, input.vertMove); // Don't allow the total movement to be more than the 1x max move speed float3 direction = inputVector / math.max(math.length(inputVector), 1); float speedMultiplier = input.IsSprinting ? settings.SprintSpeed : settings.moveSpeed; quaternion horizPlaneView = quaternion.RotateY(math.radians(view.yaw)); // Make movement vector based on player input velocity.playerVelocity = math.mul(horizPlaneView, direction) * speedMultiplier; // including jump action jump.attemptingJump = input.IsJumping; }).Schedule();
protected override void OnUpdate() { var dt = Time.DeltaTime; var predictingTick = GhostPredictionSystemGroup.PredictingTick; var gameConfig = GetSingleton <GameConfiguration>(); Entities .ForEach((ref Translation translation, ref Rotation rotation, ref Paddle paddle, in DynamicBuffer <PlayerCommand> commands, in GhostOwnerComponent ghostOwner, in PredictedGhostComponent predictedGhost) => { if (!GhostPredictionSystemGroup.ShouldPredict(predictingTick, predictedGhost)) { return; } if (!commands.GetDataAtTick(predictingTick, out PlayerCommand command)) { return; } if (command.Pushed(PlayerCommand.Up)) { paddle.Radians = AddRadians(paddle.Radians, gameConfig.PaddleSpeed * dt); } else if (command.Pushed(PlayerCommand.Down)) { paddle.Radians = AddRadians(paddle.Radians, -gameConfig.PaddleSpeed * dt); } var up = float3(0, 1, 0); var x = cos(paddle.Radians) * gameConfig.ArenaRadius; var z = sin(paddle.Radians) * gameConfig.ArenaRadius; var forward = normalize(float3(-x, 0, -z)); rotation.Value = Quaternion.LookRotation(forward, up); translation.Value = float3(x, 0, z); })
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var healthStateFromEntity = GetComponentDataFromEntity <HealthStateData>(true); var time = GetEntityQuery(ComponentType.ReadOnly <GlobalGameTime>()).GetSingleton <GlobalGameTime>().gameTime; var predictedFromEntity = GetComponentDataFromEntity <PredictedGhostComponent>(false); var PredictingTick = World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick; Entities .ForEach((ref Ability.AbilityStateIdle stateIdle, ref Ability.EnabledAbility enabledAbility, ref PredictedState predictedState) => { if (predictedFromEntity.Exists(enabledAbility.owner) && !GhostPredictionSystemGroup.ShouldPredict(PredictingTick, predictedFromEntity[enabledAbility.owner])) { return; } var shouldDash = enabledAbility.activeButtonIndex == 0 && DashAllowed(healthStateFromEntity[enabledAbility.owner]); if (shouldDash) { stateIdle.requestActive = true; predictedState.locoStartTick = time.tick; } }).Run(); return(default);
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = group.Time.DeltaTime; Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } CubeInput input; inputBuffer.GetDataAtTick(tick, out input); if (input.Horizontal > 0) { trans.Value.x += deltaTime; } if (input.Horizontal < 0) { trans.Value.x -= deltaTime; } if (input.Vertical > 0) { trans.Value.y += deltaTime; } if (input.Vertical < 0) { trans.Value.y -= deltaTime; } }); }
public void Execute([ReadOnly] ref Velocity velocity, ref Translation position, [ReadOnly] ref PredictedGhostComponent prediction) { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } position.Value.xy += velocity.Value * deltaTime; }
protected override void OnUpdate() { var tick = m_GhostPredictionSystemGroup.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((DynamicBuffer <PlayerInput> inputBuffer, ref Translation trans, ref PhysicsVelocity pv, in PredictedGhostComponent prediction, in PlayerMovementSpeed pms) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } PlayerInput input; inputBuffer.GetDataAtTick(tick, out input); var speed = pms.speed; /*if (input.horizontal > 0) * trans.Value.x += speed * deltaTime; * if (input.horizontal < 0) * trans.Value.x -= speed * deltaTime; * if (input.vertical > 0) * trans.Value.z += speed * deltaTime; * if (input.vertical < 0) * trans.Value.z -= speed * deltaTime;*/ // cosi' non rimbalza ma lagga e ci mette un po' ad accelerare if (input.horizontal > 0) { pv.Linear.x += speed * deltaTime; } if (input.horizontal < 0) { pv.Linear.x -= speed * deltaTime; } if (input.vertical > 0) { pv.Linear.z += speed * deltaTime; } if (input.vertical < 0) { pv.Linear.z -= speed * deltaTime; } if (input.firstJump) { pv.Linear.y = 8f; input.firstJump = false; } /* * un altro modo per far muovere l'oggetto è generando un impulso lineare (using Unity.Physics.Extensions): * Itero su tutte le entities che hanno i componenti PhysicsVelocity e PhysicsMass (+ PlayerMovementSpeed * e l'input del Player, nel nostro caso DynamicBuffer<PlayerInput>), quindi imposto la direzione * dell'impulso con: * float3 direction = new float3(horizontalInput, 0.0f, verticalInput); * e applico l'impulso lineare utilizzando il metodo seguente: * PhysicsComponentExtensions.ApplyLinearImpulse(ref velocity, physicsMass, direction * movement.Force */ }).ScheduleParallel();
protected override void OnUpdate() { Dependency.Complete(); var time = GetEntityQuery(ComponentType.ReadOnly <GlobalGameTime>()).GetSingleton <GlobalGameTime>().gameTime; var playerControlledStateFromEntity = GetComponentDataFromEntity <PlayerControlled.State>(true); var characterPredictedDataFromEntity = GetComponentDataFromEntity <Character.PredictedData>(false); var characterStartPositionFromEntity = GetComponentDataFromEntity <CharacterControllerMoveQuery>(false); var characterVelocityFromEntity = GetComponentDataFromEntity <CharacterControllerVelocity>(false); var predictedFromEntity = GetComponentDataFromEntity <PredictedGhostComponent>(false); var PredictingTick = World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick; Entities .ForEach((ref Ability.EnabledAbility activeAbility, ref Ability.AbilityStateActive stateActive, ref Settings settings, ref PredictedState predictedState) => { if (!characterVelocityFromEntity.HasComponent(activeAbility.owner) && predictedFromEntity.Exists(activeAbility.owner) && !GhostPredictionSystemGroup.ShouldPredict(PredictingTick, predictedFromEntity[activeAbility.owner])) { return; } var command = playerControlledStateFromEntity[activeAbility.owner].command; var charPredictedState = characterPredictedDataFromEntity[activeAbility.owner]; var startPosition = characterStartPositionFromEntity[activeAbility.owner]; startPosition.StartPosition = charPredictedState.position; characterStartPositionFromEntity[activeAbility.owner] = startPosition; var phaseDuration = time.DurationSinceTick(predictedState.locoStartTick); if (phaseDuration >= settings.dashDuration) { stateActive.requestCooldown = true; return; } //GameDebug.Log($"{predictedState.locoStartTick} :: {time.tick}"); var velocity = predictedState.startVelocity; if (predictedState.locoStartTick + 1 == time.tick) { var dashVel = settings.dashDistance / settings.dashDuration; var moveYawRotation = Quaternion.Euler(0, command.lookYaw + command.moveYaw, 0); var moveVec = moveYawRotation * Vector3.forward; velocity = moveVec * dashVel; velocity.y = 0f; predictedState.startVelocity = velocity; //GameDebug.Log($"predictedState.startVelocity {predictedState.startVelocity}"); } var oldVel = characterVelocityFromEntity[activeAbility.owner]; oldVel.Velocity = velocity; characterVelocityFromEntity[activeAbility.owner] = oldVel; }).Run(); }
protected override void OnUpdate() { var barrier = m_Barrier.CreateCommandBuffer().ToConcurrent(); var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities .WithBurst() .ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer <PlayerInput> inputBuffer, ref PhysicsVelocity v, ref PredictedGhostComponent prediction, in Translation t, in PlayerTag player) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } Player.PlayerInput input; inputBuffer.GetDataAtTick(tick, out input); if (input.Left) { v.Linear.x = player.speed; } if (input.Right) { v.Linear.x = -player.speed; } if (input.Up) { v.Linear.y = player.jumpForce; } //if (input.Down) // t.Value.y -= speed; if (input.Shoot) { /*Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(0, 1, 0), Color.red); * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(0, -1, 0), Color.red); * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(1, 0, 0), Color.red); * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(-1, 0, 0), Color.red);*/ var stencilEntity = barrier.CreateEntity(entityInQueryIndex); barrier.AddComponent(entityInQueryIndex, stencilEntity, new VoxelStencilInput { centerX = t.Value.x, centerY = t.Value.y, fillType = false, radius = 1f, shape = VoxelShape.Circle }); } }).ScheduleParallel();
protected override void OnUpdate() { var predictionGroup = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = predictionGroup.PredictingTick; var deltaTime = Time.DeltaTime; Entities.WithAll <BulletTagComponent>().ForEach((ref Translation position, in PredictedGhostComponent prediction, in Velocity velocity) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } position.Value.xy += velocity.Value * deltaTime; }).ScheduleParallel();
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities.ForEach((ref ServerPuckData puck, ref PhysicsVelocity vel, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } LimitPuckVelocitySystem.SetVel(ref vel); }); }
protected override void OnUpdate() { var deltaTime = m_PredictionGroup.Time.DeltaTime; var currentTick = m_PredictionGroup.PredictingTick; Entities .ForEach((ref Translation position, in VelocityComponent velocity, in PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(currentTick, prediction)) { return; } position.Value.xyz += velocity.Linear * deltaTime; }).ScheduleParallel();
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities.ForEach((DynamicBuffer <CharacterSyncData> inputBuffer, ref MovableComponent movable, ref LookRotationComponent rotatable, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } inputBuffer.GetDataAtTick(tick, out CharacterSyncData input); //这里只需要将数据进行更改 movable.Direction = rotatable.Direction = new float3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities .WithBurst() .ForEach((DynamicBuffer <Player.PlayerInput> inputBuffer, ref SpriteInformation sd, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } Player.PlayerInput input; inputBuffer.GetDataAtTick(tick, out input); if (input.Left && input.Right) { sd.animation = 0; } else if (input.Left) { sd.direction = SpriteInformation.Direction.LEFT; sd.animation = 1; } else if (input.Right) { sd.direction = SpriteInformation.Direction.RIGHT; sd.animation = 1; } else { sd.animation = 0; } if (input.Down && input.Up) { sd.animation = 0; } else if (input.Down || input.Up) { sd.animation = 1; } }).ScheduleParallel(); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; var entityManager = EntityManager; Entities.ForEach((Entity ent, DynamicBuffer <PilotInput> inputBuffer, ref PredictedGhostComponent prediction, in CameraRigChild cameraRigChild) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } inputBuffer.GetDataAtTick(tick, out PilotInput input); entityManager.SetComponentData(ent, new CameraRigChild { Value = cameraRigChild.Value, headPose = input.head.positon, headRot = input.head.rotation, leftHandPose = input.leftHand.positon, leftHandRot = input.leftHand.rotation, rightHandPose = input.rightHand.positon, rightHandRot = input.rightHand.rotation }); var cameraRig = entityManager.GetComponentData <CameraRigData>(cameraRigChild.Value); entityManager.SetComponentData(cameraRig.head, new Translation { Value = cameraRigChild.headPose }); entityManager.SetComponentData(cameraRig.head, new Rotation { Value = cameraRigChild.headRot }); entityManager.SetComponentData(cameraRig.leftHand, new Translation { Value = cameraRigChild.leftHandPose }); entityManager.SetComponentData(cameraRig.leftHand, new Rotation { Value = cameraRigChild.leftHandRot }); entityManager.SetComponentData(cameraRig.rightHand, new Translation { Value = cameraRigChild.rightHandPose }); entityManager.SetComponentData(cameraRig.rightHand, new Rotation { Value = cameraRigChild.rightHandRot }); }).Run(); }
protected override void OnUpdate() { if (!s_IsEnabled) { return; } var tick = m_GhostPredictionSystemGroup.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((ref Translation trans, in PredictedGhostComponent predictedGhost) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, predictedGhost)) { return; } // Make sure we advance by one unit per tick, makes it easier to debug the values trans.Value.x += deltaTime * 60.0f; }).ScheduleParallel(); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup> (); var tick = group.PredictingTick; var projectiles = projectileQuery.ToEntityArray(Allocator.TempJob); var projectilePositions = projectileQuery.ToComponentDataArray <Translation> (Allocator.TempJob); var projectileId = projectileQuery.ToComponentDataArray <ProjectileComponent> (Allocator.TempJob); Entities.ForEach((ref Translation trans, ref MovableCubeComponent cube, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } Rectangle rect = new Rectangle { x = trans.Value.x - 0.5f, y = trans.Value.z - 0.5f, width = 1, height = 1 }; for (var j = 0; j < projectiles.Length; j++) { if (projectileId[j].playerId != cube.PlayerId) { Circle circle = new Circle { x = projectilePositions[j].Value.x, y = projectilePositions[j].Value.z, radius = 0.5f }; if (CircleToRectangle(circle, rect)) { // UI.Instance.updatePlayerScore (cube.PlayerId); // Death trans.Value = new float3(0, 0.5f, 0); PostUpdateCommands.SetComponent(projectiles[j], new Translation { Value = new float3(100, 0, 100) }); } } } }); projectiles.Dispose(); projectilePositions.Dispose(); projectileId.Dispose(); }
protected override void OnUpdate() { var tick = predictionGroup.PredictingTick; Entities .ForEach((Entity entity, ref Translation translation, in DynamicBuffer <TestInput> inputBuffer, in PredictedGhostComponent prediciton) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediciton)) { return; } if (!inputBuffer.GetDataAtTick(tick, out var input)) { return; } translation.Value.y += 1.0f * input.Value; }).Run();
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PhysicsVelocity vel, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } CubeInput input; inputBuffer.GetDataAtTick(tick, out input); if (input.horizontal > 0) { vel.Linear.x += deltaTime * 10; } if (input.horizontal < 0) { vel.Linear.x -= deltaTime * 10; } if (input.vertical > 0) { vel.Linear.z += deltaTime * 10; } if (input.vertical < 0) { vel.Linear.z -= deltaTime * 10; } if (input.up > 0) { vel.Linear.y += deltaTime * 10; } if (input.reset) { trans.Value.xyz = new float3(0, 3, 0); } }); }
protected override void OnUpdate() { // Camera position default. var position = Camera.main.transform.position; var camRotation = Camera.main.transform.rotation; //GameObject ui = GameObject.FindGameObjectWithTag("UI"); var health = UI.vida; var killer = UI.KillerIdName; var playerid = UI.PlayerIdName; // Get the player entity. var commandTargetComponentEntity = GetSingletonEntity <CommandTargetComponent>(); var commandTargetComponent = GetComponent <CommandTargetComponent>(commandTargetComponentEntity); var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities.WithoutBurst(). ForEach( (Entity entity, in PlayerData playerData, in Translation translation, in Rotation rotation, in DynamicBuffer <PlayerInput> inputBuffer, in PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } // Only update when the player is the one that is controlled by the client's player. if (entity == commandTargetComponent.targetEntity) { PlayerInput input; inputBuffer.GetDataAtTick(tick, out input); currentCameraRotationX -= input.xRot * 0.0025f; currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, -85f, 85f); position.x = translation.Value.x; position.y = 1; position.z = translation.Value.z; camRotation = math.mul(rotation.Value, quaternion.RotateX(currentCameraRotationX)); health = playerData.currentHealth; killer = playerData.killedByID; playerid = playerData.playerId; } }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; // Get all of the controlled cube entities in the world, all of which have a CubeInput buffer // as well as a translation (i.e. position) and a prediction component which will magically // determine if we should apply this input or if there's some crazy prediction stuff going on. Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } // Get the input buffer data CubeInput input; inputBuffer.GetDataAtTick(tick, out input); // Apply the input if (input.horizontal > 0) { trans.Value.x += deltaTime; } if (input.horizontal < 0) { trans.Value.x -= deltaTime; } if (input.vertical > 0) { trans.Value.z += deltaTime; } if (input.vertical < 0) { trans.Value.z -= deltaTime; } }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities.ForEach( (Entity entity, DynamicBuffer <PlayerInput> inputBuffer, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } // This is a debug which will kill you when you interact inputBuffer.GetDataAtTick(tick, out var input); if (input.IsInteracting) { PostUpdateCommands.AddComponent <Kill>(entity); } } ); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var characterPredictedDataFromEntity = GetComponentDataFromEntity <Character.PredictedData>(false); var characterMoveResultFromEntity = GetComponentDataFromEntity <CharacterControllerMoveResult>(true); var characterVelocityFromEntity = GetComponentDataFromEntity <CharacterControllerVelocity>(true); var predictedFromEntity = GetComponentDataFromEntity <PredictedGhostComponent>(false); var PredictingTick = World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick; Entities .ForEach((ref Ability.EnabledAbility activeAbility, ref Ability.AbilityStateActive stateActive, ref Settings settings, ref PredictedState predictedState) => { if (!characterMoveResultFromEntity.HasComponent(activeAbility.owner)) { return; } if (predictedFromEntity.Exists(activeAbility.owner) && !GhostPredictionSystemGroup.ShouldPredict(PredictingTick, predictedFromEntity[activeAbility.owner])) { return; } var charPredictedState = characterPredictedDataFromEntity[activeAbility.owner]; var query = characterMoveResultFromEntity[activeAbility.owner]; var velocity = characterVelocityFromEntity[activeAbility.owner]; // Manually calculate resulting velocity as characterController.velocity is linked to Time.deltaTime var newPos = query.MoveResult; var newVelocity = velocity.Velocity; charPredictedState.velocity = newVelocity; charPredictedState.position = newPos; characterPredictedDataFromEntity[activeAbility.owner] = charPredictedState; }).Run(); return(default);
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((DynamicBuffer <InputCommandData> inputBuffer, ref Translation pos, ref Rotation rot, ref PredictedGhostComponent prediction) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } InputCommandData input; inputBuffer.GetDataAtTick(tick, out input); // 回転行列を求める var rotation = Quaternion.AngleAxis(input.angleH, new float3(0, 1, 0)) * Quaternion.AngleAxis(input.angleV, new float3(1, 0, 0)); var dir = rotation * front; pos.Value += new float3(dir) * input.speed * deltaTime; rot.Value = rotation; }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup> (); var tick = group.PredictingTick; var deltaTime = Time.DeltaTime; Entities.ForEach((Entity entity, ref Translation trans, ref PredictedGhostComponent prediction, ref InitProjectileComponent projectile) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } trans.Value = projectile.origin; PostUpdateCommands.RemoveComponent <InitProjectileComponent> (entity); }); Entities.ForEach((ref Translation trans, ref PredictedGhostComponent prediction, ref ProjectileComponent projectile) => { if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } trans.Value += projectile.vector * deltaTime * 3f; }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <GhostPredictionSystemGroup>(); var tick = group.PredictingTick; Entities.ForEach((ref MainPlayerData mainPlayer, ref Translation targetTranslation) => { int playerId = mainPlayer.teamID; Translation target = targetTranslation; Entities.ForEach((ref MovableCubeComponent player, ref FixToTargetData targetData, ref Translation cubeTranslation, ref PredictedGhostComponent prediction) => { if (player.PlayerId != playerId) { return; } if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) { return; } FollowCenterBlockSystem.SetPos(target, targetData, ref cubeTranslation); }); }); }
protected override void OnUpdate() { // TODO (mogensh) put this check into its own system. Can we enable/disable systems depending on configvars ? if (CharacterModule.PredictionCheck.IntValue > 0) { var timeQuery = EntityManager.CreateEntityQuery(ComponentType.ReadOnly <GlobalGameTime>()); var time = timeQuery.GetSingleton <GlobalGameTime>().gameTime; var query = EntityManager.CreateEntityQuery(typeof(Character.PredictedData), typeof(PredictedGhostComponent)); var predictedDataArray = query.ToComponentDataArray <Character.PredictedData>(Allocator.TempJob); var entityArray = query.ToEntityArray(Allocator.TempJob); for (int i = 0; i < predictedDataArray.Length; i++) { if (!GhostPredictionSystemGroup.ShouldPredict(World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick, EntityManager.GetComponentData <PredictedGhostComponent>(entityArray[i]))) { continue; } var predictedData = predictedDataArray[i]; if (predictedData.tick > 0 && time.tick != predictedData.tick + 1) { GameDebug.Log("Update tick invalid. Game tick:" + time.tick + " but current state is at tick:" + predictedData.tick); } predictedData.tick = time.tick; EntityManager.SetComponentData(entityArray[i], predictedData); } entityArray.Dispose(); predictedDataArray.Dispose(); timeQuery.Dispose(); query.Dispose(); } base.OnUpdate(); }