• Register

The game you are trying to view has ceased development and consequently been archived. If you are a member of this game, can demonstrate that it is being actively developed and will be able to keep this profile up to date with the latest news, images, videos and downloads, please contact us with all details and we will consider its re-activation.

A one-level (singleplayer / splitscreen multiplayer) racing game project done for educational purposes.

Report article RSS Feed Splitscreen input

How to make input keys for two players on the same screen (for the splitscreen multiplayer mode.)

Posted by feillyne on Oct 17th, 2010
Basic Other.

After starting a Unity project (or booting original Unity car-racing one).

1. Select Edit -> Project Settings -> Input

2. In CarEdu, Fire Axes (Fire1, Fire2, Fire3) were removed, and only 11 were left:
Horizontal, Vertical, Handbrake, Mouse X, Mouse Y, Mouse ScrollWheel, Window Shake X, Window Shake Y, Horizontal2, Vertical2, Handbrake2

As you can see, also Jump axes were renamed to Handbrake axes, and instead of having two Horizontal (Horizontal, Horizontal), there is Horizontal and Horizontal2. The number 2 points out which players own which "axes", i.e. keys.

In Horizontal axis Alt Negative Button and Alt Positive Button settings were erased.
In Horizontal2 axis alt Negative and Positive buttons were defined ("a" and "d" keyboard keys), and other options (such as Gravity, Dead, Sensitivity, Snap, etc.) were made after Horizontal.

Also notice change in Joy Num property - it was changed to Joystick 1, and Joystick 2, respectively.

Same was done for Vertical (Vertical, Vertical2) axes.

Also, Handbrakes were set appropriately. You can compare them all with input settings of the original Car-racing tutorial by Unity.

See pictures below to see the everything done.

Input Manager - Horizontal axes

Input Manager - Vertical axes

Input Manager - handbrakes

Mouse X, Mouse Y, Mouse ScrollWheel, Window Shake X, Window Shake Y axes were left untouched.

Also, notice that in Project section, in the directory Scripts/JavaScripts, there is a new script Car2.js that was created using duplication function of Unity (CTRL + D).

The entire class Wheel was removed from the Car2 script, since only one class with such a name can exist.

javascript code:
class Wheel
  var collider : WheelCollider;
  var wheelGraphic : Transform;
  var tireGraphic : Transform;
  var driveWheel : boolean = false;
  var steerWheel : boolean = false;
  var lastSkidmark : int = -1;
  var lastEmitPosition : Vector3 = Vector3.zero;
  var lastEmitTime : float = Time.time;
  var wheelVelo : Vector3 = Vector3.zero;
  var groundSpeed : Vector3 = Vector3.zero;

Then look at the code itself of Car2.js. What has changed? Can you spot it? ;-)

As you can see, we need to allow both players to control their respective cars (or characters if you make your own game with the splitscreen multiplayer). So we scroll down to this function:

javascript code:
function GetInput()
  throttle = Input.GetAxis("Vertical2");
  steer = Input.GetAxis("Horizontal2");

In this function, there are two different axes for each player, see below.

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

throttle = Input.GetAxis("Vertical2");
steer = Input.GetAxis("Horizontal2");

Vertical2 and Horizontal2 are names of the axes you set earlier in Input Manager. If you renamed your second Horizontal to e.g. Player2Horizontal, and your second Vertical axis to Player2Vertical, you would have to set such axes:

throttle = Input.GetAxis("Player2Vertical");
steer = Input.GetAxis("Player2Horizontal");

So proper keys are mapped to proper players.

You need to set handbrakes right, too. You need to find CheckHandbrake() function in Car.js. Below its code and structure:

javascript code:
function CheckHandbrake()
      handbrake = true;
      handbrakeTime = Time.time;
      dragMultiplier.x = initialDragMultiplierX * handbrakeXDragFactor;
  else if(handbrake)
    handbrake = false;
    StartCoroutine(StopHandbraking(Mathf.Min(5, Time.time - handbrakeTime)));

There's a line that will interest us most:

As you can figure out, there is another button set for the second player.


The "r" keyboard key will be used by the second player to brake.

Also remember to set the Car2 object itself to the Car2.js script, by clicking Car2 object and dragging Car2.js script onto the car, as below:

Car2.js script\

All done. :-)

Post comment Comments
Guest Sep 5 2013, 11:38am says:

This comment is currently awaiting admin approval, join now to view.

Guest Sep 20 2013, 11:18pm says:

This comment is currently awaiting admin approval, join now to view.

Guest Jun 7 2014, 3:58am says:

This comment is currently awaiting admin approval, join now to view.

Guest Mar 3 2015, 6:37am says:

This comment is currently awaiting admin approval, join now to view.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Windows, Mac
Developed By
Send Message
Release Date
Game Watch
Track this game
Report Abuse
Report article
Related Games
CarEdu Single & Multiplayer Racing
Related Engines
Unity Commercial Released May 30, 2005
Related Groups
Indie Devs
Indie Devs Hobbies & Interests group with 1,176 members
Unity devs
Unity devs Hobbies & Interests group with 1,300 members