Sunday 30 March 2014

Unity Tips: Swipe controls for Android and iOS

I've been doing a bit of work in Unity lately, putting together a basic Android game to teach myself the basics. I wanted to use swipe controls to move the player, and I think I've come up with a pretty nice template I thought I'd share with any other beginners out there. It's based on this script by Sushanta Chakraborty, but I've made it a bit more powerful and responsive. A brief explanation is below for those still learning C#.

using UnityEngine;
using System.Collections;

public class SwipeControl : MonoBehaviour
{
    //First establish some variables
    private Vector3 fp; //First finger position
    private Vector3 lp; //Last finger position
    public float dragDistance;  //Distance needed for a swipe to register

    // Update is called once per frame
    void Update()
    {
        //Examine the touch inputs
        foreach (Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Began)
            {
                fp = touch.position;
                lp = touch.position;
            }
            if (touch.phase == TouchPhase.Moved)
            {
                lp = touch.position;
            }
            if (touch.phase == TouchPhase.Ended)
            {
                //First check if it's actually a drag
                if (Mathf.Abs(lp.x - fp.x) > dragDistance || Mathf.Abs(lp.y - fp.y) > dragDistance)
                {   //It's a drag
                    //Now check what direction the drag was
                    //First check which axis
                    if (Mathf.Abs(lp.x - fp.x) > Mathf.Abs(lp.y - fp.y))
                    {   //If the horizontal movement is greater than the vertical movement...
                        if (lp.x>fp.x)  //If the movement was to the right
                        {   //Right move
                            //MOVE RIGHT CODE HERE
                        }
                        else
                        {   //Left move
                            //MOVE LEFT CODE HERE
                        }
                    }
                    else
                    {   //the vertical movement is greater than the horizontal movement
                        if (lp.y>fp.y)  //If the movement was up
                        {   //Up move
                            //MOVE UP CODE HERE
                        }
                        else
                        {   //Down move
                            //MOVE DOWN CODE HERE
                        }
                    }
                }
                else
                {   //It's a tap
                    //TAP CODE HERE
                }

            }
        }
}

Ok, so what's happening here? 

Friday 28 March 2014

Review: Yorkshire Tea

The first thing you need to know about Yorkshire Tea is that it's not actually from Yorkshire. If, like me, you were expecting, nay, hoping, for a vast, Eden Project-esque biome covering the North York Moors, filled with tea fields, you will be disappointed. The name is purely a branding exercise exploiting the fact that the company selling the tea was founded by a Swiss man who opened a tea shop in Harrogate, which, for our foreign readers, is in the West Riding of Yorkshire, which is in England, which is part of Great Britain, which is part of the United Kingdom of Great Britain and Northern Ireland, which is mostly situated on the British Isles. While the brand itself has been around for a while, it started advertising fairly vigorously about five years ago, and has been getting product placement from TV shows and celebrities and so on, which is odd, for tea. But then, so is trying to market 'Yorkshireness' as a desirable commodity.

But enough preamble. What's the tea like? Well, to answer that I probably ought to tell you a little about my tea-drinking preferences; in areas of taste there's almost no objective handle to be found, and so one must understand the subjective biases of the reviewer in order to parse and render their opinions. I am a Strong Tea man. I like my elements so mixed that a spoon might stand up in them. However, I am also a man of Taste. No PG Tips or Tetleys for me. 'But those are strong teas!' I hear you cry. Yes, they are. But, just as one can desire strong alcohol without wanting to drink prison lavatory wine, one can like strong tea without wanting PG Tips. It is not that it is too strong for me; it is that it is unbelievably shit. When I drink a gin and tonic it is mostly gin, but it is good gin. So, strength and refinement, that's me. If I weren't engaged this would probably make an excellent dating profile.

My spirits were raised, then, when I looked at the side of the box and saw that it recommended a full five minutes of brewing time. 'This', I said, filling the teapot, 'is a tea that demands to be strong'. I was wrong.

Yorkshire Tea is incredibly bland. The five minutes brewing time is recommended because if you gave it any less you'd be drinking a mug of hot, grey, diluted milk. It's not that the taste is unpleasant - quite the opposite - it's just that there's very little of it. And, bizarrely, it's not a question of concentration. I tried two bags, then three; then leaving it for ten minutes, then fifteen; then stirring - and it didn't make the slightest bit of difference. No matter how strong you make it, the flavour never really manifests itself.

It's driving me a little bit mad. I bought a several-thousand-bag chest of it from Tesco because they were out of everything else, and now I haven't had a proper cup of tea for weeks. I'm drinking it as fast as I can, but that just makes it worse, because the cravings keep getting stronger and stronger. I'm currently editing a fifteenth-century manuscript due in for Wednesday, and I'm staying up all night to get it done, and I haven't had anything to drink for so long and I really need it and GIVE ME A GOD-DAMN CUP OF TEA I WILL BURN THIS PLACE TO THE GROUND






Thursday 13 March 2014

Thief and Stealth Systems

Yes, I know I'd said that this would be about plausible level design, but that's taking me rather longer to research than I expected, so instead let's talk about stealth systems. What I want to do here is define the characteristics of stealth in the original Thief games (particularly T1 and T2), compare these to stealth in Thief, and examine how the stealth systems have affected the rest of the game.1

In the beginning we lived as thieves

The easiest way to describe the stealth systems in Thief is to list the ways in which the player could be discovered by the AI. You could be seen, heard, or noticed. By 'noticed', I mean that a guard could become aware of your presence not because they saw you, but because they saw something you had done to the world, such as the dead or unconscious body of a guard. 'Noticing' is probably the area which changed the most over the course of the series: guards in T1 only responded to bloodstains or bodies, but by T:DS they could notice open doors, doused torches and missing loot. Covering most of one's tracks was easy, but hiding bodies was a slower process that frequently caused the player to become more exposed. In the first two games, bloodstains could only be removed by water arrows, forcing the player to balance the risk of a guard discovering them against the cost of the arrow.

Monday 10 March 2014

Thief in Brief

I finished Thief on the day it came out, and I’ve been trying to write a review ever since. It currently stands at around 11,000 words – far too long, even for a blog as self-indulgent and meandering as this one,1 and so instead putting out one massive review, I’m going to write a series of posts covering various aspects of the game such as level design, stealth, etc., and my thoughts about those aspects of games in general. For now, though, a review in miniature.