void Move(VirtualJoystick.MOVE_DIR _moveDir) { switch (_moveDir) { case VirtualJoystick.MOVE_DIR.UP: targetTilePos = gameGrid.GetCellToWorld(new Vector3Int(playerCellPos.x, playerCellPos.y + 1, playerCellPos.z)); break; case VirtualJoystick.MOVE_DIR.DOWN: targetTilePos = gameGrid.GetCellToWorld(new Vector3Int(playerCellPos.x, playerCellPos.y - 1, playerCellPos.z)); break; case VirtualJoystick.MOVE_DIR.LEFT: targetTilePos = gameGrid.GetCellToWorld(new Vector3Int(playerCellPos.x - 1, playerCellPos.y, playerCellPos.z)); break; case VirtualJoystick.MOVE_DIR.RIGHT: targetTilePos = gameGrid.GetCellToWorld(new Vector3Int(playerCellPos.x + 1, playerCellPos.y, playerCellPos.z)); break; } // Move to target cell if (_moveDir != VirtualJoystick.MOVE_DIR.NONE) { Vector2 direction = (targetTilePos - playerPos).normalized; body.MovePosition((Vector2)pawn_sprite.transform.position + direction * (moveStat.moveSpeed * Time.deltaTime)); } }
void RenderOtherPlayersAnim(Animator _animator, VirtualJoystick.MOVE_DIR _dir) { if (_dir == VirtualJoystick.MOVE_DIR.LEFT) { _animator.transform.localScale = new Vector3(1, 1, 1); } else if (_dir == VirtualJoystick.MOVE_DIR.RIGHT) { _animator.transform.localScale = new Vector3(-1, 1, 1); } _animator.SetFloat("NormalizeSpd", (int)_dir); }
void UpdateMovement() { playerPos = pawn_sprite.transform.position; playerCellPos = gameGrid.GetWorldFlToCellPos(playerPos); if (prevCellPos != playerCellPos) { tileRefManager.SetTile(TileRefManager.TILEMAP_TYPE.TILEMAP_PLAYER, prevCellPos, null); prevCellPos = playerCellPos; } if (tileRefManager.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_PLAYER, playerCellPos) != tileRefManager.GetTileRef(TileRefManager.TILE_TYPE.TILE_WARNING)) { tileRefManager.SetTile(TileRefManager.TILEMAP_TYPE.TILEMAP_PLAYER, playerCellPos, tileRefManager.GetTileRef(TileRefManager.TILE_TYPE.TILE_WARNING)); } if (MyNetwork.instance.IsOnlineGame()) { if (!isServer) { CmdUpdateMoveDir(dpad.GetMoveDir()); } else { dpad_moveDir = dpad.GetMoveDir(); } } Move(dpad.GetMoveDir()); RenderAnim(); //if (targetTilePos != Vector2.zero) //{ // if (playerPos != targetTilePos) // { // pawn_sprite.transform.position = Vector2.MoveTowards(playerPos, targetTilePos, Time.deltaTime); // } // else // { // if (!b_reachedTarget) // { // gameGrid.SetTile(TileRefManager.TILEMAP_TYPE.TILEMAP_PLAYER, gameGrid.GetWorldFlToCellPos(playerPos), originalTile); // b_shownCrossTiles = false; // b_reachedTarget = true; // } // } //} }
void SyncSpriteAnimations() { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); for (int i = 0; i < players.Length; i++) { if (players[i].GetComponent <NetworkIdentity>().isLocalPlayer) { continue; } Animator _animator = players[i].transform.GetChild(1).GetChild(0).GetComponent <Animator>(); VirtualJoystick.MOVE_DIR _dir = players[i].GetComponent <PlayerMoveController>().dpad_moveDir; players[i].GetComponent <PlayerMoveController>().RenderOtherPlayersAnim(_animator, _dir); } }
void CmdUpdateMoveDir(VirtualJoystick.MOVE_DIR _dir) { dpad_moveDir = _dir; }