- Home /
How to make multiple players control one vehicle (A controls movement, B controls turret)
I try to make a coop game were one player can control the vehicles movement and the other can aim with the turret. So far I used Unet and Photon to achieve my goal but i dont get it to work. Any suggestions on how to approach this problem?
Can you detail on what you have tried and why isn't it working?
i stated the question in the forums: http://forum.unity3d.com/threads/how-to-make-a-gunner-driver-coop-game.401951/
i tried to raise an event by the player that should be carried out by the avatarcontroller. It kinda works but the client never has impact on the host ( when i move with the host, the client sees the changes but not vice versa) if you want i could also give you the whole project to play around with.
The information you provided seems very high level, so I'm going to give you a high level answer. From your post in the other forum, it looks like your approach is to pass movement input to the server, which is safe and simple but is prone to delayed reaction (ie: I press forward, and the car starts driving 0.4 seconds later). Not ideal for actions that require fast response time, like steering.
One way you could accomplish your goal of having player A control turret and player B control vehicle movement is to give them local authority over those game objects (at least over their position/orientation (pose) and velocity. Then, when player A fires turret, you have player A client send information of from where and in what direction the bullet was fired on his screen. Note that what player A saw when he shot a bullet (ie: enemy is in scope) will be different from what the server saw because of lag.
Thanks for the answer ;) I tried to give local authority to the controlled object (in photon) but i dont really know how to do it. the $$anonymous$$i Tutorial on the Photon webside plus the tutorial about taking or requesting authority didnt help me a whole lot :( i think i didnt really get it. Is there a very simple example of how to give authority to an object on start of the game? And how to properly send and recieve from client to server and vice versa. Id like to do it in photon because i can test the game via cloud at once but if someone knows an example for unet, id take it as well ;)
i am quite new to network coding and it might be that i didnt really figure out how the system works. especially talking about the host client (the one i start on unity itself) and the client client (the one executed from a build). I tried to rename each player to Player1, Player2...in the Network$$anonymous$$anager (Photon) right after he was instanciated by PhotonNetwork.Instanciate() but it only worked for the first one...the second one was never renamed...
This is how i impemented the Player spawning/rena$$anonymous$$g
const string VERSION = "v0.0.1";
public string roomName = "ZwuselRoom";
public string playerPrefabName = "Ship";
public Transform[] spawnPoints;
private GameObject player;
private int playerNum = 1;
// Use this for initialization
void Start()
{
PhotonNetwork.ConnectUsingSettings(VERSION);
}
void Update()
{
}
void OnConnectedTo$$anonymous$$aster()
{
Debug.Log("Connected to " + PhotonNetwork.Server);
}
void OnJoinedLobby()
{
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 3 };
PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
Debug.Log("Joined Lobby");
}
void OnCreatedRoom()
{
Debug.Log("Created Room");
}
void OnJoinedRoom()
{
player = PhotonNetwork.Instantiate(playerPrefabName, spawnPoints[0].position, spawnPoints[0].rotation, 0);
NamePlayer(player);
Debug.Log(player + " joined Room");
}
void NamePlayer(GameObject player)
{
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
bool playerExists = false;
for (int i = 0; i < players.Length; i++)
{
if (players[i].name == "Player" + playerNum)
{
playerExists = true;
Debug.Log(players[i].name + " exists.");
}
}
if (!playerExists)
{
Debug.Log(player.name + " to Player" + playerNum);
player.name = "Player" + playerNum;
}
playerNum++;
}
ty folks!
fabian.mkv pointed me in the right direction and it works now...at least in my simple example script. Here is how i did it ;) http://forum.unity3d.com/threads/how-to-make-a-gunner-driver-coop-game.401951/
Your answer
Follow this Question
Related Questions
How to configure keys to let to players play 3 Answers
Any clues on how to create a split-screen effect like the lego harry potter game? 3 Answers
How do i Make a Co-Op game. 1 Answer
Free Multiplayer? 1 Answer
2 Player - best way 0 Answers