Revolutionary: WRX Stage 1

The training wheel project got me thinking about what more it would take to create a Wii racing rig that's as comprehensive as a traditional wheel and pedal gaming setup. The Wii Wheel provides analog control for steering, but not throttle and braking. The Wheel shell also blocks off the expansion port, so you can't use a Nunchuk's analog stick. It seemed like there was just no way to build a full set of racing controls around the Wii Wheel, but then I got my Balance Board and the wheels started turning in my head. How about a Wii Racing Xperiment?

Some stiff competitionWith a few unusual exceptions, I've avoided writing racing scripts. It just never seemed like the strengths of the Wiimote could be leveraged well enough against its weaknesses to do justice to my favorite genre. What I wanted was simple enough – analog throttle and brakes to go with my motion-based analog steering. To meet my demands, the Balance Board would have to have to work like a set of analog racing pedals. Variable amounts of foot pressure would translate to variable amounts of throttle or brakes.

Testing of the board revealed that it could provide analog sensitivity, but it would take some runtime calibration to make it behave similarly on different Balance Boards. I decided to use PPJoy to get true analog control instead of emulating it through keyboard presses as I've primarily done in the past. PPJoy is supported through GlovePIE with several functions for both analog and digital control types. After you get it installed, using PPJoy in a game is as easy as selecting it as your game controller.

Keep in mind, this script is written assuming that you're connecting your Balance Board before your Wiimote. If you connect them in the opposite order, you will have to change the numbering in the script. It seems to take a moment for GlovePIE to start recording values from the Balance Board, so because we need to get an initial reading as a baseline for the rest of the script, I make GlovePIE wait a moment at the beginning of the script to give it time to start reading the Balance Board.

wait 20ms //Short wait before getting initial Balance Board values
PPjoy.Analog1 = 0 //Resets the "pedals" at the beginning of the loop
if !var.init
var.BBJy = Wiimote1.BalanceBoard.JoyX
var.init = True
EndIf
var.BBy = Wiimote1.BalanceBoard.JoyX - var.BBJy //Subtracts the initial values from the current values

Make sure the Balance Board is on a level surface and nothing is resting on it when you start this script. The values collected in the above bit of code will be used to set the input at 0, since it doesn't read as 0 to start with.

If var.BBy < 0
var.BBy = (var.BBy * 9)
EndIf

The left side of the Balance Board wasn't as responsive as the right, so I multiplied any input to the left of the center point by a factor of 9. The values coming from the BalanceBoard.Joy function were still too low to correspond directly with PPJoy.Analog, so I had to multiply it again to get the range from 0 to 1 on the right side and -1 to 0 on the left side working with me applying a comfortable amount of foot pressure to the board.

var.BBy = (var.BBy * 25) //Decrease this number if you want to press harder
PPjoy.Analog1 = var.BBy

Next I set a deadzone, so that I could lightly rest my foot on the Balance Board without a response. Increasing this number widens the deadzone for those of you with feet more leaden than my own.

If (PPjoy.Analog1 > .25 or < -.25)
PPjoy.Analog1 = PPjoy.Analog1
Else
PPjoy.Analog1 = 0
EndIf



Converting Wii controller inputs into joystick vectors can sometimes be tricky if we're dealing with motion sensing and axes, but writing the controls for Wii Wheel steering was one of the most effortless undertakings I've faced in all my GlovePIE scripting days.

PPJoy.Analog0 = maprange(Wiimote2.SmoothPitch,-80,80,-1,1) //Steering controls
PPJoy.Digital0 = Wiimote2.1 //Digital button 0
PPJoy.Digital1 = Wiimote2.2 //Digital button 1
PPJoy.Digital2 = Wiimote2.B //Digital button 2
PPJoy.Digital3 = Wiimote2.A //Digital button 3
Key.Up = Wiimote2.Right //Menu up
Key.Down = Wiimote2.Left //Menu down
Key.Left = Wiimote2.Up //Menu left
Key.Right = Wiimote2.Down //Menu right
Key.Esc = Wiimote2.Minus //Menu back
Key.Enter = Wiimote2.Plus //Menu enter
Shift + P + I + E = Any.Home //Stops script running

The Wheel, as configured above, has 160° of rotation. Turning it beyond that will not affect any greater response, unless you turn it past 90° in either direction, which will make the controller think you're turning from the other direction. So long as you have both hands on the wheel, you probably won't turn quite it that far and there shouldn't be any problems. If you want to take the Wiimote out of the Wheel shell and play Excite Truck-style, increasing the range to 170° (85 and -85) works a little better.

To see what values are being sent to PPJoy, I added a debug line.

debug = "B Board: " + PPjoy.Analog1 + ", Wheel: " + PPjoy.Analog0

I loaded up Need for Speed ProStreet, changed my controller to PPJoy and configured the controls in the game and then it was off to the races.


The Balance Board and Wii Wheel, a winning combination

It's been disappointing seeing the racing genre so under-represented on the Wii. Aside from Mario Kart Wii, there aren't many noteworthy racers on this platform, and before the Balance Board arrived, there was good cause. Now I've seen what's possible and I'm hopeful that developers will take advantage of the peripheral for racers and other unexpected game types.

This is just the first stage on the experiment. Need for Speed ProStreet has several more controls that can be mapped, and PPJoy is just begging to be mapped to them. Driving simulators also have some complex controls that can overwhelm the average steering wheel and pedal controller set, but future stages in the Wii Racing Xperiment will attempt to implement more. We wouldn't expect an actual Wii game to be made much more complicated than what's been done in this stage, but I got into writing these scripts because I wanted to push the limits. If you have any suggestions on how I could do that, feel free to share in the comments.

Every Tuesday, Mike Sylvester brings you REVOLUTIONARY, a look at the wide world of Wii possibilities. The Wii Balance Board by itself opens up a world of possibilities, and with GlovePIE, you can help make it more than just a fitness gadget. Let Revolutionary: Balance and Options introduce you to the new toy that all the scripters want to play with.

This article was originally published on Joystiq.