public override void ExecuteCommand(Command command, bool resetState) { PlayerInputCommand cmd = (PlayerInputCommand)command; if (resetState) { transform.position = cmd.Result.position; transform.rotation = Quaternion.Slerp(transform.rotation, cmd.Result.rotation, 0.3f); rb.velocity = cmd.Result.velocity; rb.angularVelocity = cmd.Result.angularVelocity; if (cmd.Input.exit) { BoltNetwork.Detach(gameObject); Application.Quit(); } } else { if (cmd.IsFirstExecution) { ProcessInput(cmd); cmd.Result.position = transform.position; cmd.Result.rotation = transform.rotation; cmd.Result.velocity = rb.velocity; cmd.Result.angularVelocity = rb.angularVelocity; } } }
public override void SimulateController() { input.ReadInput(false); IPlayerInputCommandInput commandInput = PlayerInputCommand.Create(); commandInput.right = input.right; commandInput.forward = input.forward; commandInput.roll = input.roll; commandInput.up = input.up; commandInput.pitch = input.pitch; commandInput.yaw = input.yaw; commandInput.exit = input.exit; entity.QueueInput(commandInput); }
private void ProcessInput(PlayerInputCommand cmd) { rb.AddRelativeForce(cmd.Input.right * movementForce, cmd.Input.up * movementForce, cmd.Input.forward * movementForce, ForceMode.Impulse); LookUpdate(cmd.Input.roll, cmd.Input.pitch, cmd.Input.yaw); //rb.AddRelativeTorque(cmd.Input.pitch, cmd.Input.yaw, cmd.Input.roll, ForceMode.Acceleration); }
private void EndCommand(GameCommand gameCommand) { // Figure out what to do. FrameCommand command = null; switch (gameCommand) { case GameCommand.Up: // Stopped accelerating upwards, update directions if something changed. RemoveAccelerationDirection(Directions.Up); break; case GameCommand.Down: // Stopped accelerating downwards, update directions if something changed. RemoveAccelerationDirection(Directions.Down); break; case GameCommand.Left: // Stopped accelerating leftwards, update directions if something changed. RemoveAccelerationDirection(Directions.Left); break; case GameCommand.Right: // Stopped accelerating rightwards, update directions if something changed. RemoveAccelerationDirection(Directions.Right); break; case GameCommand.Stabilize: // Stopped stabilizing, should we toggle? if (Settings.Instance.StabilizeToggles) { // Toggle stabilizers. command = new PlayerInputCommand( _stabilizing ? PlayerInputCommand.PlayerInputCommandType.BeginStabilizing : PlayerInputCommand.PlayerInputCommandType.StopStabilizing); _stabilizing = !_stabilizing; } else { // Disable stabilizers if not toggling. command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.StopStabilizing); _stabilizing = false; } break; case GameCommand.Shield: // Stopped shielding, should we toggle? if (Settings.Instance.ShieldToggles) { // Toggle shields. command = new PlayerInputCommand( _shielding ? PlayerInputCommand.PlayerInputCommandType.BeginShielding : PlayerInputCommand.PlayerInputCommandType.StopShielding); _shielding = !_shielding; } else { // Disable shields if not toggling. command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.StopShielding); _shielding = false; } break; case GameCommand.Shoot: // Stop shooting. if (_shooting) { command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.StopShooting); _shooting = false; } break; } // If we did something, push it. if (command != null && IsConnected && !_game.Client.Paused && !_game.GameConsole.IsOpen) { _game.Client.Controller.PushLocalCommand(command); } }
private void BeginCommand(GameCommand gameCommand) { // Figure out what to do. FrameCommand command = null; switch (gameCommand) { case GameCommand.Up: // Started accelerating upwards, update directions if something changed. AddAccelerationDirection(Directions.Up); break; case GameCommand.Down: // Started accelerating downwards, update directions if something changed. AddAccelerationDirection(Directions.Down); break; case GameCommand.Left: // Started accelerating leftwards, update directions if something changed. AddAccelerationDirection(Directions.Left); break; case GameCommand.Right: // Started accelerating rightwards, update directions if something changed. AddAccelerationDirection(Directions.Right); break; case GameCommand.Rotate: // Rotation changed and we should send the new target rotation. command = new PlayerInputCommand( PlayerInputCommand.PlayerInputCommandType.Rotate, new Vector2(_targetRotation, 0)); break; case GameCommand.Accelerate: // Acceleration vector changed and we should send the new one. command = new PlayerInputCommand( PlayerInputCommand.PlayerInputCommandType.Accelerate, _accelerationVector); break; case GameCommand.Stabilize: // Enable stabilizers if not toggling. if (!Settings.Instance.StabilizeToggles && !_stabilizing) { command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.BeginStabilizing); _stabilizing = true; } break; case GameCommand.Shield: // Enable shield if not toggling. if (!Settings.Instance.ShieldToggles && !_shielding) { command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.BeginShielding); _shielding = true; } break; case GameCommand.ZoomIn: // Zoom camera in. if (IsConnected) { _game.Client.GetSystem <CameraSystem>().ZoomIn(); } break; case GameCommand.ZoomOut: // Zoom camera out. if (IsConnected) { _game.Client.GetSystem <CameraSystem>().ZoomOut(); } break; case GameCommand.Shoot: // Shoot. if (!_shooting) { command = new PlayerInputCommand(PlayerInputCommand.PlayerInputCommandType.BeginShooting); _shooting = true; } break; case GameCommand.Use: // TODO break; case GameCommand.PickUp: // Pick up nearby items. command = new PickUpCommand(); break; case GameCommand.Back: // TODO break; case GameCommand.Menu: // TODO break; case GameCommand.Inventory: // TODO break; case GameCommand.Character: // TODO break; case GameCommand.ToggleGraphs: // Toggle performance and network graph display. _game.GraphsVisible = !_game.GraphsVisible; break; case GameCommand.Console: // Toggle console. _game.GameConsole.IsOpen = !_game.GameConsole.IsOpen; break; case GameCommand.TestCommand: //Testing time /* * var move = new MoveCamera * { * Player = 0, * Position = new List<MoveCamera.Positions>(), * Return = true, * ReturnSpeed = 10 * }; * var positions = new MoveCamera.Positions {Speed = 10, Zoom = 0.3f}; * move.Position.Add(positions); * positions = new MoveCamera.Positions {Destination = new FarPosition(51000, 49000), Speed = 10}; * move.Position.Add(positions); * move.Position.Add( * new MoveCamera.Positions {Destination = new FarPosition(51000, 49000), Speed = 100, Zoom = 0.7f}); * _game.Client.GetSystem<CameraMovementSystem>().Move(move); */ break; } // If we did something, push it. if (command != null && IsConnected && !_game.Client.Paused && !_game.GameConsole.IsOpen) { _game.Client.Controller.PushLocalCommand(command); } }