I want to create a 2-player online card game using Unity, but I’m having issues with card movement functionality.
As shown in the diagram, when Player 1 (right side) draws a card from their deck, the card should move to their hand area towards the lower left. For Player 2 (left image), they should see the card moving from Player 1’s deck (opponent’s side) towards the upper right to Player 1’s hand area (opponent’s side).
However, my current issue is that Player 2 sees the card moving in the same direction as Player 1 sees it.
I’m using Mirror for networking. When modifying Sync Direction, the error pattern changes - cards might move from hand to deck instead, and the error can occur on either the Host or Client.
Since the game has multiple zones, I prefer to control card movement start/end points programmatically rather than using animations. I’m trying to implement this using Update() or IEnumerator.
Below is my partial code and the card’s inspector. Currently, the server side is showing errors while the Client side works correctly.
Cards’ script
void Update()
{
NetworkIdentity networkId = NetworkClient.connection.identity;
playerManager = networkId.GetComponent<PlayerManager>();
if (isPointing)
{
if (Input.GetKeyUp(KeyCode.H) & isControllable & transform.parent.transform != myHandArea.transform)
{
playerManager.CmdMoveCard(gameObject, "Hand");
}
}
if (isMoveCard > 1)
{
transform.position = Vector2.MoveTowards(transform.position, targetArea.transform.position, 10);
isMoveCard -= 1;
}
else if (isMoveCard == 1)
{
isMoveCard = 0;
transform.SetParent(targetArea.transform, false);
targetArea = null;
}
}
PlayerManager
[Command]
public void CmdMoveCard(GameObject card, string target)
{
RpcMoveCard(card, target);
}
[ClientRpc]
void RpcMoveCard(GameObject card, string target)
{
CardBehavier cardBehavier = card.GetComponent<CardBehavier>();
if (target == "Hand")
{
if (isOwned)
{
cardBehavier.targetArea = myHandArea;
}
else
{
cardBehavier.targetArea = enemyHandArea;
}
}
cardBehavier.isMoveCard = 30;
}
my sync direction of card is client to server