Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by falconer · Feb 12, 2013 at 11:21 AM · multiplayercar game

split screen multiplayer car game?

Hello, I'm creating a car game, I was thinking of adding a split screen multiplayer game feature. I'm stuck at a point, I need help real badly, I need to submit this work within 7 days. I have added two cars in a scene which use the same script, but the problem is both are controlled by the same keys. When i press the UP ARROW or the key W both the cars move, tried to edit the key settings from Edit>Project settings> Input. But again both the car controls were edited. I want one car to be controlled by W,S,A,D and other with U,J,H,K. Somebody please help me with this.

P.S : throttle = Input.GetAxis("Vertical"); steer = Input.GetAxis("Horizontal");

This is the part of the code which gets the input.

Comment
Add comment · Show 2
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 FLASHDENMARK · Feb 12, 2013 at 12:14 PM 0
Share

Add the input-string to a variable. This will allow you to define unique input to each different car which means that each car will not be controller by both users.

EG:

var throttleInput : String; //"Vertical" for car 1 and "Vertical 2" for the second car.

Just remember to have these inputs defined in the input settings.

avatar image falconer · Feb 13, 2013 at 08:21 AM 0
Share

Got it! Thank you :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Novodantis · Feb 12, 2013 at 11:48 AM

You can create new inputs in the Input Manager by increasing the number at the top. Copy the buttons & axis' that you need and name them "Horizontal 2", "Vertical 2" etc.

Then add a variable on the car to define which player controls them. You can then have a condition in your code that decides which set of controls to accept. An example (js):

 var playerID : int;    // the player whose car this is
 var acceleration : float; // throttle (replace this, it's just to illustrate)
 
 function Update() {
   if (playerID == 1) {
     // player 1 controls, eg
     acceleration = Input.GetAxis("Vertical");
   } else if (playerID == 2) {
     // player 2 controls
     acceleration = Input.GetAxis("Vertical 2");
   }
 }

Don't forget to set the value of Player ID in the inspector, to the player that controls a given car. Please note there is large room for improvement here, but I hope it illustrates the principle.

Comment
Add comment · Show 1 · Share
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 falconer · Feb 13, 2013 at 08:22 AM 0
Share

Got it! Thank you!

avatar image
1

Answer by Shaolin-Dave · Apr 18, 2015 at 04:48 PM

For more expandability, try this...

 function Update() {
    if (playerID == 1) {
      // player 1 controls, eg
      acceleration = Input.GetAxis("Vertical");
    } else {
      // all other player controls
      acceleration = Input.GetAxis("Vertical " + playerID);
    }
  }

And if you can rename "Vertical" to "Vertical 1" (might require more research), this would be even better.

 function Update() {
     acceleration = Input.GetAxis("Vertical " + playerID);
  }
Comment
Add comment · Show 1 · Share
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 Novodantis · Jun 29, 2015 at 09:37 PM 0
Share

Indeed - even better!

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

How to make a local multiplayer game? With one device as input. 0 Answers

Stopping the car aftert he finish line? 1 Answer

Starting a multiplayer car game only by the server? 1 Answer

Network.InitializeServer doesn't work over Internet 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