Multiple simultaneous mice; Avoiding key repeat; Multi-click

Hi!

I have had a lot of fun trying out Unity over the past month, and I have contributed music and 3D content to a prior effort that was helmed by a more capable Unity guru. I just purchased my own Indie license, and want to get started making some awesome stuff!

So, for my next trick, I am going to make a game that is targeted at stylus users (Wacom tablets), with aspirations of getting it on the Wii down the road. Mice users won’t be left out, but the game will not require the unique abilities of a mouse at all (read continuous scrolling in a 2-D coordinate system).

The Wii supports four remotes, pointing at the screen, at once. However, I have never heard of even two mice being used at the same time (and I have tried this myself).

QUESTION 1: Is it even possible to have more than one pointer flying around (one for each mouse/stylus+tablet), or do I need to wait for computers to become more friendly in general before I can make a proper multiplayer-on-one-screen computer game? Also, can I create multiplayer games with Unity that would utilize a LAN or Internet connection, if I need a workaround?

I know two of the exact same input device can be used, because I have used two Dance Dance Revolution mats at the same time, with many Macs, and my girlfriend and I play with two very similar Saitek controllers. Mice may be a special case, though.

If I can get this working, I will at some point make a game that uses a mouse in one hand and a stylus in the other, but the current development will work for people with only one hand, as long as they have a two-button mouse.

Now, for compatibility for people with one-button mice, I plan to allow the use of a key instead of right-clicking. I’m pretty sure that I have played games where the space bar is used for gas, and it functions continuously, but the standard function of all non-modifier keys is to repeat at a certain rate when they are held down.

QUESTION 2: How does key repeating apply within Unity?

I would like to allow the Right Mouse Button or an equivalent key to be held down, performing a function all the while. It would not be good for this function to be toggled on and off at a constant rate.

I have come up with the current control scheme with the idea that both mouse buttons cannot be used at the same time. With the Wii, I plan to use A Button=Left Click and B Button=Right Click/(other Key), but A and B can be used together on the Wii.

QUESTION 3: Can left-and right-click be used at the same time? If not, if I am holding the right mouse button, and left-click, what happens?

Control-clicking is generally the same thing as right-clicking , but is that a definition or merely a workaround?

Lastly, about that key in question, I was planning on using the space bar, but then remembered that I haven’t been able to use anything other than modifier keys at the same time as clicking. (This is a serious issue in Logic, for example, because you can’t play notes with the keyboard and drag an on-screen pitch bend wheel at the same time.)

QUESTION 4: Will I be able to hold the space bar down and click at the same time? Furthermore, if I use a modifier key instead of the space bar, will I be able to click while holding that without invoking another “click-action” that would interrupt the continuous operation of the modifier key?

Thanks in advance for any input that anyone can give me in regards to all of this. In an effort to make the controls as simple as possible, I just find myself running into a lot of complications!

Off the top of my head:

  1. Lemmings on Amiga used two mice at once for multiplayer, and it was INSANE fun!

  2. More than one system pointer, no. More than one GAME pointer, yes: they’d be objects or HUD textures rather than true OS cursors. I don’t know about 2 mouse hardware devices though. Might need a custom C plugin?

Unity can make 'net multiplayer games too, but (at the moment) you must handle that yourself via .NET. (I seem to recall rumors of friendlier multiplayer in Unity 2? I could be wrong.)

  1. You can handle inputs any way you like–constant down or one-time trigger. No worries about key repeats.

  2. You can use both mouse buttons at once (if your mouse supports that–I’m looking at YOU mighty mouse!), but I don’t think Ctrl is the equivalent unless you program it to be so (could be wrong).

I’ve never heard of problems clicking and using keys at once. Sounds like a Logic thing. Can you play FPS games?

  1. Yes–multiple simultaneous inputs are no problem. My game responds to mouse, keys, and two joysticks all at once (if you’re that crazy).

Yes to answer 2 at least.

I just coded a test of a “power bar” in a game that uses this function. For the alpha builds of the game instead of a traditional GUI bar that stretches (as yet to do) I simply am using a GUIText object to show a percentage strength from 0-100.

I set it up so that if a user holds down the left arrow the power counter rapidly counts down to 0. If the right arrow is held down, it rapidly counts up to 100.

I can post the script if you’d like.

Is that what you’re asking?

Weird…never heard of any issues like that; certainly no problems here. That would render an awful lot of games unplayable if that were actually the case. Maybe it’s your keyboard. Usually keyboards have some limit to the number of keys that can be pressed at once, but it’s nothing that anyone should typically have any issues with unless you’re trying to type by pressing your entire hand down on the keyboard. :wink: As far as using more than one mouse at the same time, I know of Mouse Party (used in Big Kahuna Reef), but I don’t know if/how you can use that with Unity.

–Eric

I believe it is, and I welcome the good news.

About the keys + click issues, it must be an incredibly specific problem. For instance, if I type while click-holding in Safari’s address bar, my text won’t appear until after I release the mouse button. However, while still click-holding, I can type all I want and see it immediately in this forum entry box.

That’s specific–games won’t suffer from that. Safari thinks you’re doing a drag-select I bet.

Here’s the associated code, I called it PowerBarTest.js …

// this shows up in the inspector, a GUIText object in your scene gets dragged onto it and attached to link it
var displayPower : GUIText;

var Max = 100;
var Min = 0;
var bar = 0;

function Start () {
	displayPower.text = "0";	
}

function Update ()
{
	// go into Input Settings, increase the number there by two, and define them as poweradd and powersubtract
	// and set them to use right and left (or keys of you like such as A and S) respectively
	if (Input.GetButton("poweradd")) {
	   if (bar <= Max) {
	       bar++;
	       displayPower.text = "" + bar;
        }
    }
    
    if (Input.GetButton("powersubtract")) {
        if (bar >= Min) {
	       bar--;
	       displayPower.text = "" + bar;
        }
    }
}

My version’s sloppy but it works well. Thanks to Sector3 for thinking this through and supplying the basis of this code.

The problem is that’s going to be framerate-dependent. i.e., the speed at which the bar value goes up and down depends on how fast the game’s running. Also I’d recommend using axis input instead of individual buttons, which simplifies the coding for positive/negative input like this. To make it framerate-independent involves a float value instead of an integer and multiplying by Time.deltaTime, and throw in a sensitivity variable as well so you can control how fast up/down it goes. Then use ToString to display just the integer part:

var displayPower : GUIText; 

var max = 100; 
var min = 0; 
var bar : float = 0;
var sensitivity : float = 20;

function Update () 
{ 
   // go into Input Settings, increase the number there by one, and define it as power 
   // and set it to use right and left for positive and negative (or keys if you like such as A and S) respectively 

   bar += Input.GetAxis("power") * Time.deltaTime * sensitivity;
   bar = Mathf.Clamp(bar, min, max);
   displayPower.text = bar.ToString("f0"); 
}

To simplify it a bit more, you could attach that script to the GUIText object directly and get rid of the “var displayPower : GUIText;” line, and change references of “displayPower” to “guiText”.

–Eric