/// <inheritdoc /> public void Tick() { bool changed = false; float horizontal = Input.GetAxis("Horizontal"); if (Math.Abs(LastHoritzontalInput - horizontal) > 0.005f) { changed = true; LastHoritzontalInput = horizontal; } float vertical = Input.GetAxis("Vertical"); if (Math.Abs(LastVerticalInput - vertical) > 0.005f) { changed = true; LastVerticalInput = vertical; } //If the input has changed we should dispatch to anyone interested. if (changed) { OnMovementInputDataChanged?.Invoke(this, new MovementInputChangedEventArgs(vertical, horizontal)); } }
/// <inheritdoc /> public void Tick() { if (!isLocalPlayerSpawned) { return; } bool changed = false; float horizontal = Math.Sign(InputController.CurrentHorizontal); if (Math.Abs(LastHoritzontalInput - horizontal) > 0.005f) { changed = true; LastHoritzontalInput = horizontal; } float vertical = Math.Sign(InputController.CurrentVertical); if (Math.Abs(LastVerticalInput - vertical) > 0.005f) { changed = true; LastVerticalInput = vertical; } //Add the elaspsed milliseconds. if (isBroadcastingHeartbeat) { HeartBeatCounter += Time.deltaTime * 1000f; } if ((int)HeartBeatCounter > HEARTBEAT_MILLISECOND_TIME) { Debug.Log("Sending heartbeat movement."); } //If the input has changed we should dispatch to anyone interested. if (changed || (int)HeartBeatCounter > HEARTBEAT_MILLISECOND_TIME) { MovementInputChangedEventArgs args = new MovementInputChangedEventArgs(vertical, horizontal, !changed && HeartBeatCounter > HEARTBEAT_MILLISECOND_TIME); OnMovementInputDataChanged?.Invoke(this, args); //Always reset heartbeat on send. HeartBeatCounter = 0.0f; isBroadcastingHeartbeat = args.isMoving; //if moving we should be broadcasting heartbeat data } }