public override void ExecuteCommand(Command command, bool resetState) { base.ExecuteCommand(command, resetState); if (entity.isOwner) { IPlayerMoveCommandInput cmd = (IPlayerMoveCommandInput)command; state.isFacingRight = cmd.velocity.x >= 0; rigidbody2D.AddForce(cmd.velocity); if (rigidbody2D.velocity.magnitude > topSpeed) { rigidbody2D.velocity = rigidbody2D.velocity.normalized * topSpeed; } if (cmd.jump && isGrounded) { rigidbody2D.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse); } if (cmd.fire) { if (currentWeapon != null) { currentWeapon.Fire(); } } } }
public override void SimulateController() { base.SimulateController(); IPlayerMoveCommandInput moveCommand = PlayerMoveCommand.Create(); Vector2 move = new Vector2(); if (Input.GetKey(KeyCode.A) && isGrounded) { //Left move move += Vector2.left * acceleration; } if (Input.GetKey(KeyCode.D) && isGrounded) { //Right move move += Vector2.right * acceleration; } moveCommand.velocity = move; if (Input.GetKeyDown(KeyCode.Space) && isGrounded) { moveCommand.jump = true; } if (Input.GetKeyDown(KeyCode.Return)) { moveCommand.fire = true; } entity.QueueInput(moveCommand); }