2013年1月13日日曜日

Minecraft with Wii nunchuck


Do you want to play Minecraft with Wii nunchuck?

I (and maybe many people) expected that Minecraft:  Xbox 360 edition supports Microsoft Kinect but my guess was wrong. Calmly thinking of using Kinect for Minecraft, it would very difficult for provide stress-free, confortable interaction. We still have a chance for update but this was one reason why I made this sketch. Playing Minecraft by using gestures would be fun, I thought.

Thanks to Nintendo's backward compatibility policy, Wii nunchuck controller is not obsolute yet in spite of launching Wii U. We can buy it easily.

Wii nunchuck was hacked around 2009. I2C is it's communication protocol and you can see it's data format from Windmeadow Labs website.

Read wii nunchuck data into arduino - Windmeadow Labs

I made some sketches about it around 2009. I reused and modified it for the first time in a while.

This time, I used Arduino Leonard. Differs from other Arudinos such as Arduino UNO, it can behave as a HID keyboard and mouse. The Leonard receives status values of two buttons, 2-axis joystick and 3-axis accelerometer from Wii nunchuck.  These values are translated to keyboard and mouse events for playing Minecraft, and these events are sent to the connected PC.

Connecting Arduino and Wii nunchuck


To hook up a Wii nunchuck to Arduino, using "WiiChuck Adapter" is one of the easiest way to do it. You can buy this small PCB from Sparkfun Electronics or some other online electric parts shops. I simply cut my universal PCB and made my own WiiChuck Adapter clone. The look of this is not good but this works perfectly.



All you need is to hook up 4 pins (GND, 3.3V, D2, D3).

D2 : SDA (serial data)
D3 : SCL (serial clock)

Arduino Leonard has independent pins SCL and SDA. You may use these pins.

Software


WiiChuck class encapslates Wii nunchuck's I2C communication through wire library.  You can download it from Arduino Playground.

Arduino Playground - WiiChuck Class

I added a few methods for convenience. My all source code is here.

How to play


Wii nunchuckKeyboard & MouseAction
Roll/TiltMouse moveLook around the world
Joystick[W],[A],[S],[D]Move forward/backward/left/right
Joystick (a little press)[W],[A],[S],[D] + Left shiftCrouching/sneaking move
Shake Wii nunchuckMouse left clickBreak down/mine blocks
C + Shake Wii nunchuck[Q]Drop a held item
CMouse right clickPlace the resource
ZSpaceJump
C + Roll joystickMouse wheelSelect the held item from your inventory hot bar
C + Z[E]Open/close your inventory window
C + Z + Joystick down (hold 3secs)-(Special command) Grab/Release control

To break down blocks, you need to keep shaking your Wii nunchuck. This gesture is equivalent to click and hold the left mouse button. It enables you feel as if you were a real Minecraft character. You can also dash by double clicking your Wii nunchuck's joystick.

Grab/release control is Wii nunchuck control "ON/OFF". It's for safety measure to prevent from unintended keyboard and mouse emulation.

You can watch how it works from this YouTube video:


Still a little bit awkward especially Joystick rolling and tilting response but it's enjoyable and you can even eat popcorn while playing!

0 件のコメント:

コメントを投稿