void UpdateServerClients() { using (var dicIterator = inputsByClientID.GetEnumerator()) while (dicIterator.MoveNext()) { TransformPacket transformPacket = new TransformPacket(); TransformData transformData; EnemySpaceship enemySpaceship = dicIterator.Current.Value.spaceship; Vector3 accumulatedInputs = Vector3.zero; List <InputPacket> inputs = dicIterator.Current.Value.inputs; if (inputs.Count > 0) { for (int i = 0; i < inputs.Count; i++) { float[] movement = inputs[i].Payload.movement; Vector3 inputVector = new Vector3(movement[0], movement[1], movement[2]); accumulatedInputs += inputVector; } enemySpaceship.Move(accumulatedInputs); float[] spaceshipPosition = { enemySpaceship.transform.position.x, enemySpaceship.transform.position.y, enemySpaceship.transform.position.z, }; transformData.flags = (int)TransformFlag.PositionBit | (int)TransformFlag.InputSequenceIDBit; transformData.inputSequenceID = inputs[inputs.Count - 1].Payload.sequenceID; transformData.position = spaceshipPosition; transformData.rotation = null; transformData.scale = null; transformPacket.Payload = transformData; inputs.Clear(); PacketsManager.Instance.SendPacket(transformPacket, null, dicIterator.Current.Key, enemySpaceship.ObjectID); } } }
void UpdateOtherClients() { using (var dicIterator = otherClientsTransformsByID.GetEnumerator()) while (dicIterator.MoveNext()) { EnemySpaceshipTransformData enemySpaceshipTransformData = dicIterator.Current.Value; if (enemySpaceshipTransformData.previousTransform != null) { EnemySpaceship enemySpaceship = enemySpaceshipTransformData.spaceship; float[] lastPositionValues = enemySpaceshipTransformData.lastTransform.Payload.position; float[] previousPositionValues = enemySpaceshipTransformData.previousTransform.Payload.position; Vector3 lastPosition = new Vector3(lastPositionValues[0], lastPositionValues[1], lastPositionValues[2]); Vector3 previousPosition = new Vector3(previousPositionValues[0], previousPositionValues[1], previousPositionValues[2]); if ((lastPosition - enemySpaceship.transform.position).sqrMagnitude > NeglibiglePosDiffSqrMagnitude) { Vector3 direction = (lastPosition - previousPosition).normalized; enemySpaceship.Move(direction); } } } }