Archive for September, 2010

Hometown GP : Launched!

Posted in Games, Unity on 2010/09/11 by duck

I’m really pleased to announce that our new game, “Hometown GP“, has been launched!

Hometown GP Screenshots

This is the latest browser based racing game from us at Skive, this one being a Formula 1 racer with a unique feature: By using a custom Google Maps interface, you can create your own tracks on real roads – pretty much anywhere in the world – and the game will dynamically generate a 3D racetrack which matches your route.

The idea is to be able to experience Formula 1 coming to your home town – so you could create a route which goes along your street, past your local shops or school, etc. Of course you can also choose to build anywhere else in the world too, if you feel like exploring! Combining Flash and Unity 3D technologies with route, altitude and satellite data from Google maps, this project breaks new ground when it comes to technology “Mash-Ups”.

If you’re logged in and finish 3 laps of your new track, it gets saved to the database and will show up as a marker pin along with everyone else’s tracks around the map of the world. You can share your tracks via facebook and twitter, and challenge your friends to beat your times on any course.

Here’s a video of the game in action:

Notable features:

  • Intuitive custom track designer built on Google’s route finding technology.
  • Dynamic 3D world created to match your design.
  • Analysis of real satellite & terrain data used to decide placement of trees, buildings and open space.
  • Real altitude data used to create track height and surrounding hills.
  • Realistic scales and Formula 1 speeds.
  • Dynamic driving assistance adapts to your performance – casual gamers and skilled drivers alike should find the game equally enjoyable without the need to fiddle with menus and settings.
  • Community features allow you to race other people’s tracks, and share your tracks with others.
  • Adaptive quality degradation ensures very high visual quality on high-spec machines, while low-spec machines prioritise framerate – without the need for manual settings.

You can play the the game here:

http://racing.vodafone.com/hometown

However you might also like to try some of these direct links to tracks which I think show off the game quite well:
(try and beat my times on these!)

And finally, some stills – for those of you who like that kind of thing!

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Hometown GP Screenshot

Quick Tip : How to choose which way to turn?

Posted in Code and Scripting, Quick Tips, Unity on 2010/09/07 by duck

Often situations arise in game coding – particularly in AI – where you need to be able to calculate which way to turn in order to reach a certain angle.

Certain types of motion in Unity allow you to avoid this question altogether, such as Slerping (a.k.a. using spherical interpolation) from one rotation to another. Sometimes you need to be more explicit in your code however, and in these cases you often need to deal with and make decisions based on the angles themselves.

Some situations involve completely free-moving objects that need to turn in any direction, such as a spaceship that can fly in any direction in 3d space. Other times, you have more constrained situations (eg, a boat, car, or any other object which is turning but constrained to some kind of surface) where you simply want to decide between a clockwise or anticlockwise direction when turning.

This tip tackles the latter of the two, where you need to make a decision about turning clockwise or anticlockwise based on arbitrary rotations or directions as input.

An example of this would be an AI controlled car, which might need to turn towards a target (another car, or the next waypoint, for example). You don’t want to use interpolation, because that would preclude realistic car physics. You wouldn’t want it making a 270 degree turn to reach a target that was 90 degrees to the left, but how to determine which way to turn?

These situations usually boil down to one of the following cases, where you need to find:

  1. the angle between two rotations,
  2. the angle between a rotation and a target position,
  3. the angle between a rotation and a target direction, or
  4. the angle between two direction vectors

The key to solving anyof the above lies in the fact that whichever case you have, you can convert it to the last case – where you simply have two directional vectors to compare – and from there you can use a few simple math functions to return the angle you want. Unity provides some very useful functions in its API which help along the way.

Starting at case 1, you have two rotations (which in Unity are represented by Quaternions).

A rotation can be converted to a directional vector by multiplying the quaternion by the world-relative “forward” direction. Forward in Unity is represented by the positive direction along the Z axis (i.e. 0,0,1) and there is a handy alias to this value on the Vector3 class called “.forward“, so assuming “rotationA” and “rotationB” are our quaternions, we can get our two directional vectors like this:

// convert both rotations to direction vectors:
var forwardA = rotationA * Vector3.forward;
var forwardB = rotationB * Vector3.forward;

It’s also worth noting that in most cases in Unity, when you’re dealing with a rotation, it is very likely to have come from a GameObject with a transform. If this is the case, there’s an easier method of getting the forward vector, which is to use the built-in variable: transform.forward which directly gives you an object’s forward direction as a vector:

var forwardA = objectA.transform.forward;
var forwardB = objectB.transform.forward;

Now looking at case 2, where we have a rotation and a target position. Assuming we’re working with gameobjects, we can use the transform.forward of our object that is trying to turn towards the target (eg, the car) for the forward direction, and if this script is placed on the car itself, it’s as simple as this:

var forwardA = transform.forward;

To get the direction vector towards the target (case 3), we just need to subtract the target’s position from the car’s position, like this:

var forwardB = target.position - transform.position;

You should now have two directional vectors whose angles you want to compare to each other.

The final part of the puzzle lies in the fact that you want a signed angle (i.e. either a positive or negative angle). That is, you want to know more than just the numeric difference in angles, you want to know whether to turn clockwise or anticlockwise to get there. To get a signed angle doesn’t really make a lot of sense in 3D space, because the direction of rotation from one direction to another could be in any 3d direction (not just in one of two ‘flat’ clockwise/anticlockwise directions).

For this reason, it usually makes sense to compare your vectors on a certain chosen 2D plane, and ignore the 3rd axis. For example, in the case of cars you’d probably want to compare the “Top Down” directions as if on a map, ignoring the inclines of hills. This would be the X-Z plane in Unity.

To convert these vector directions to numeric angles in this way, you can use the Atan2 function, like this:

// get a numeric angle for each vector, on the X-Z plane (relative to world forward)
var angleA = Mathf.Atan2(forwardA.x, forwardA.z);
var angleB = Mathf.Atan2(forwardB.x, forwardB.z);

However, this function returns its result in radians, which is just a different scale for measuring angles, and can be converted back to degrees very simply by multiplying the result by a built-in value called Rad2Deg in Unity which is provided for just this purpose, so to have the result in degrees, the above lines would end up looking like this:

// get a numeric angle for each vector, on the X-Z plane (relative to world forward)
var angleA = Mathf.Atan2(forwardA.x, forwardA.z) * Mathf.Rad2Deg;
var angleB = Mathf.Atan2(forwardB.x, forwardB.z) * Mathf.Rad2Deg;

And finally, Unity provides a simple function for getting the signed difference between two numeric angles in degrees (which is what we’ve been working towards!) called DeltaAngle, which you would use like this:

// get the signed difference in these angles
var angleDiff = Mathf.DeltaAngle( angleA, angleB );

You now have a single numeric value which should be in the range of -180 to 180. Negative values indicates your object should turn to its left, and positive, to its right.

Hope this comes in handy out there in Unityland!

Yard Invaders 2 : experimental prototype

Posted in Games, Unity on 2010/09/02 by duck

Well, my “Procedural Racer” game has been taxiing for launch for quite a while now – as soon as it’s ready I will be posting here. In the meantime, here’s a video of an experimental gameplay prototype I put together, as a possible sequel to one of my very old 2D shockwave games called “Yard Invaders”.

I tried out a number of new things while putting this together, including:

  • Procedurally generated spherical terrain
  • Spherical gravity
  • Custom grass shader
  • Depth of field effects
  • Explosion effects (not detonator)
  • Intuitive auto-targeting of enemies

Whether this ever makes it to the status of a finished game remains subject to the mysterious tides of fate.

Follow

Get every new post delivered to your Inbox.

Join 40 other followers