Implementing Gesture Sequences in Unity* 3D with TouchScript

[Pages:10]Implementing Gesture Sequences in Unity* 3D with TouchScript

By Lynn Thompson

When configuring touch targets to control other elements of a scene, it's important to minimize the screen space that the controlling elements occupy. In this way, you can devote more of the UltrabookTM device's viewable screen area to displaying visual action and less to user interaction. One means of accomplishing this is to configure the touch targets to handle multiple gesture combinations, eliminating the need for more touch targets on the screen. An example is the continual tapping of a graphical user interface (GUI) widget, causing a turret to rotate while firing, instead of a dedicated GUI widget for firing and another for rotating the turret (or another asset in the Unity* 3D scene).

This article shows you how to configure a scene using touch targets to control the first person controller (FPC). Initially, you'll configure the touch targets for basic FPC position and rotation; then, augment them for additional functionality. This additional functionality is achieved through existing GUI widgets and does not require adding geometry. The resulting scene will demonstrate Unity 3D running on Windows* 8 as a viable platform for handling multiple gestures used in various sequences.

Configure the Unity* 3D Scene

I begin setting up the scene by importing an FBX terrain asset with raised elevation and trees, which I had exported from Autodesk 3ds Max*. I then place an FPC at the center of the terrain.

I set the depth of the scene's main camera, a child of the FPC, to -1. I create a dedicated GUI widget camera with an orthographic projection, a width of 1, and a height of 0.5 as well as Don't Clear flags. I then create a GUIWidget layer and set it as the GUI widget camera's culling mask.

Next, I place basic GUI widgets for FPC manipulation in the scene in view of the dedicated orthogonal camera. For the left hand, I configure a sphere for each finger. The left little sphere moves the FPC left, the left ring sphere moves it forward, the left middle moves it right, and the left index sphere moves the FPC backward. The left-thumb sphere makes the FPC jump and launches spherical projectiles at an angle of 30 degrees clockwise.

For the right-hand GUI widget, I create a cube (made square through the orthogonal projection). I configure this cube with a Pan Gesture and tie it to the MouseLook.cs script. This widget delivers functionality similar to that of an Ultrabook touch pad.

2 Implementing Gesture Sequences in Unity* 3D with TouchScript

I place these GUI widgets out of view of the main camera and set their layer to GUIWidget. Figure 1 shows the scene at runtime, with these GUI widgets in use to launch projectiles and manipulate the position of the FPC.

Figure 1. FPC scene with terrain and launched spherical projectiles The projectiles launched from the FPC pass through the trees in the scene. To remedy this, I would need to configure each tree with a mesh or box collider. Another issue with this scene is that the forward velocity is slow if I use the touch pad to have the FPC look down while pressing the ring finger to move the FPC forward. To resolve this issue, I limit the "look-down" angle when the "move forward" button is pressed.

Multiple Taps

The base scene contains an FPC that fires projectiles at a specified angle off center (see Figure 1). The default for this off-center angle is 30 degrees clockwise when looking down on the FPC.

10 June 2014

Implementing Gesture Sequences in Unity* 3D with TouchScript 3

I configure the scene to have multiple taps, initiated at less than a specified time differential, alter the angle at which the projectiles are launched, then launch a projectile. I can configure this behavior to increase the angle exponentially with the number of taps in the sequence by manipulating float variables in the left-thumb jump script. These float variables control the firing angle and keep track of the time since the last projectile was launched:

private float timeSinceFire = 0.0f; private float firingAngle = 30.0f;

I then configure the Update loop in the left-thumb jump script to decrement the firing angle if the jump sphere tap gestures are less than one-half second apart. The firing angle is reset to 30 degrees if the taps are greater than one-half second apart or the firing angle has decremented to 0 degrees. The code is as follows:

timeSinceFire += Time.deltaTime;

if(timeSinceFire ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download