Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Zwusel · May 04, 2016 at 06:33 PM · multiplayerco-op

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?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raresh · May 05, 2016 at 01:24 PM 0
Share

Can you detail on what you have tried and why isn't it working?

avatar image Zwusel · May 05, 2016 at 01:31 PM 0
Share

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.

avatar image fabian-mkv · May 05, 2016 at 04:34 PM 0
Share

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.

avatar image Zwusel · May 05, 2016 at 05:03 PM 0
Share

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!

avatar image Zwusel · May 06, 2016 at 10:34 AM 0
Share

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/

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges