Monday, 15 April 2013

UnityWii Issues

I have tried vigorously to get some sort of wii mechanics working which would allow the user to steer their car via wii-mote however I have ran into a few issues trying to do it.

The main issue is that the wiiyourself library is in c# language and my car movement script in javascript. Obviously it is very difficult to use variables between different types of scripts and this has proved problematic. I have tried creating a javascript variable which allows me to add the script in to access these variables which initially worked out fine.

I would have preferred to do it the other way around by accessing the c# script in my javascript file however for some reason the new version of unity doesn't allow what it did in the previous versions and after roughly 30-45 minutes trying I simply could not access the c# variables in the javascript.

I then set a couple public float variables called pitch and roll in javascript which I would then use set in the update method equivalent to the pitch and roll values of the wii remote. However after adding a similar script as above I finally realized the variable values weren't updating so nothing was happening to the cars.

After having thought through every possible solution I could I looked online for help but was just given the same sort of solution that I have already implemented. I will write another blog shortly when or if I come up with a solution.

Thursday, 11 April 2013

Getting to grips with Unity Wii

Now that the deadline for this project is near I now need to add Wii controls to add more interactivity and user feedback to my game. I haven't had any past experience with this so far so this week I just decided to test out the kit I downloaded from  https://github.com/lonewolfwilliams/WiiYourselfUnity/blob/master/README.md and see what I can come up with.

The original demo included in the kit showed the user how to rotate an object based on the rotation dimensions of the wii-mote. Although this wasn't particular relevant to my game I was interested to see what could be achieved using it and decided to apply this code to see if it would work well with a maze game. 


The controls seem a bit off but that is mainly down to the positioning of the camera. This is a good example of a game which can have multiple levels of feedback because I could have set up multiple cameras and then gave the game the option to press a key to switch between cameras for better views of the maze.

I now tried out moving a cube in unity using the wii-mote which is much more appropriate for my game. I was able to get some basic movement done by translating the players position with the following line of code.

transform.Translate(pitchRoll.pitch * Time.deltaTime, 0f, 0f);

What this line of code does it moves the cube on the x axis dependent on the pitch value, angle of the wii-mote, and times it by the delta time which allows for a smooth movement. The other two values are the Y and Z axis which are set to zero.

I think that I can use code similar to this in my car game and update the position constantly so that the movement isn't limited . I can then add in the code used to rotate the maze above to turn the car. This would work similar to the keyboard keys because if the player turns anti-clockwise the number is a negative which reverses the cube and clockwise a positive which accelerates it.