Reputation: 517
I am trying to make a multiplayer air hockey game in Unity, but encountered some problems. When the first user creates the room, the hockey puck is spawned along with the first player's mallet (the object you hit the puck with). When the second player connects to the Photon server, their mallet is spawned.
The issue is when the second player hits the puck with his mallet, the Rigidbody physics don't work on the puck. The puck slides right along the mallet, but doesn't bounce off the mallet.
I am new to Unity, so I don't know what part of the code to post. But this is the code where I spawn the items:
private void Start() {
Vector2 puckPosition = new Vector2(0,0);
Vector2 randPos = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
if(CreateAndJoinRooms.intHold == 0) { // If the user created the room, the result is 0
PhotonNetwork.Instantiate(puckPrefab.name, puckPosition, Quaternion.identity);
}
PhotonNetwork.Instantiate(playerPrefab.name, randPos, Quaternion.identity);
}
Mallet Prefab:
Puck Prefab:
Upvotes: 3
Views: 586
Reputation: 1
It sounds like the problem is with Photons object ownership. According to the images, the puck prefabs Ownership Transfer = Fixed, which means it will never change. So it's is spawned and controlled by player 1 (as the Master Client), and player 1 is responsible for moving/controlling it.
In this case, Player 1 spawns the puck, player 2 strikes it and affects its Rigidbody2D, but then the next PhotonView Transform & Rigidbody2D updates are received, which set the location & velocity according to player 1s view, ignoring player 2s impact.
A some possible solutions:
Upvotes: 0