Auto-Formatting C# in VSCode for Unity 3D

Flutter in VSCode has spoiled me: Now I want to use auto-formatting everywhere!

Luckily you can also enable this for Unity 3D & VSCode! Here is how:

  • Install VSCode
  • Install the C# Plugin
  • Set the formatter for C# to “ms-vscode.csharp”. The entry in your settings should look like this:
  • You can see how this file would look in the settings-file I use, here
  • Create a file called “omnisharp.json”, and add these lines:

{
“FormattingOptions”: {
“newLine”: “\n”,
“useTabs”: false,
“tabSize”: 2,
“indentationSize”: 2,

“NewLinesForBracesInTypes”: false,
“NewLinesForBracesInMethods”: false,
“NewLinesForBracesInProperties”: false,
“NewLinesForBracesInAccessors”: false,
“NewLinesForBracesInAnonymousMethods”: false,
“NewLinesForBracesInControlBlocks”: false,
“NewLinesForBracesInAnonymousTypes”: false,
“NewLinesForBracesInObjectCollectionArrayInitializers”: false,
“NewLinesForBracesInLambdaExpressionBody”: false,

“NewLineForElse”: false,
“NewLineForCatch”: false,
“NewLineForFinally”: false,
“NewLineForMembersInObjectInit”: false,
“NewLineForMembersInAnonymousTypes”: false,
“NewLineForClausesInQuery”: false
}
}

 

  • Here is also where you can set your auto-formatting preferences (tab-size, indentations, etc)
  • Copy this file into your Unity-Source directory. It should be next to your “Assets” folder, and the assembly-files VSCode auto-creates. Don’t forget to add it to source-control!

  • Open your Unity-Scripts from Unity in VSCode
  • Wait until the project has been properly loaded.
  • Hit Alt-Shift-F

And Voilá! Your entire code just auto-formatted itself, and saved you a lot of headaches. I was able to update 8-year-old files into my current preferred formatting with just a single key-combination!

-Matthias (@matthias_code)

Advertisement

How to use the Video Player in Unity

Do you want to make your own games with lots of cutscenes like in Command & Conquer, Wing Commander, or the newer Roundabout? In this introduction to the Unity Video Player you’ll learn how to do that, and how to implement videos in a variety of ways of your own into your game. Unity comes with its own Video Player component, which means adding videos and creating games around it is not at all complicated.

You will learn how to:

  • Start and stop full-screen cutscenes.
  • Display videos on surfaces inside the game-world.
  • Add videos from YouTube and other video-sites.
  • Create 360°-videos for your Virtual Reality app.

Getting Started

You will need the newest version of Unity, and the starter-files which you can download here. This tutorial will build on them. In that download you can also find the finished project!

You will also need to know the basics of Unity, and have already created something with it.

Load the starter-project, Land of Full Motion Video Starter, and take a look at the folder-structure inside the Assets folder.

Initial project files.

Here is what each folder contains:

  • Fonts: The font used for the in-game texts.
  • Materials: The materials used in the world, including grass and trees.
  • Models: The 3d-models used in this game.
  • Prefabs: The used objects as prefabs.
  • Scenes: The various scenes used in this tutorial.
  • Scripts: Several pre-made scripts, some of which you will extend.
  • Shader: A special occluded 3d-text shader.
  • Sounds: The sound for pressing a button.
  • Standard Assets: The first-person controller used in this game.
  • Textures: The grass and metal textures used in the game.
  • Videos: The two example videos provided with this project.

The Land of Full Motion Video

Now open up the scene 01FullScreenCutscene. It should look something like this:

Welcome to the magical Land of Full Motion Video, where 3d-environments intersect with real-life video-recordings in completely plausible ways.

Right now you can see a small environment you can explore in first-person, and a console with buttons on it. Try it out! Walk around using the wasd-keys and try to press the buttons by pointing at them and left-clicking.

Nothing will happen though. That’s what you’ll fix next. :)

First you will need to open the VideoController.cs file, which barely has anything in it! Of course nothing is playing.

Your First Cutscene

Start by adding these two methods to the VideoController class:

//1
public void PlayFullScreenOfflineVideo()
{
    StartFullScreenVideo(videoFilePath);
}

private void StartFullScreenVideo(string path)
{
    //2
    if (fullScreenVideoPlayer)
    {
        Destroy(fullScreenVideoPlayer);
    }
    
    //3
    fullScreenVideoPlayer =
        Camera.main.gameObject.AddComponent();

    //4
    firstPersonInteractor.SetImmobile(true);

    //5
    fullScreenVideoPlayer.playOnAwake = false;
    fullScreenVideoPlayer.renderMode =
        UnityEngine.Video.VideoRenderMode.CameraNearPlane;
    fullScreenVideoPlayer.targetCameraAlpha = 1F;
    fullScreenVideoPlayer.url = path;
    fullScreenVideoPlayer.frame = 0;
    fullScreenVideoPlayer.isLooping = false;

    //6
    fullScreenVideoPlayer.Play();
}

Here is what happens in the code of PlayFullScreenOfflineVideo():

  1. PlayFullScreenOfflineVideo executes when you press the button. It then calls StartFullScreenVideo() with a saved filepath as parameter.
  2. The method checks if a Video Player component already exists, and if so destroys it. As a new Video Player instantiates every button press you should be sure to removed old ones.
  3. The main camera receives the Video Player component. In this part a full-screen-video will show, and you’ll need the main camera to do that.
  4. The player-controller is set to not move. This is important so that you cannot move around during a playing cutscene and change the environment. This is a simple game, where nothing except the player actually moves. In a more complex one you’d have to be sure to pause and/or deactivate everything that could affect a change on the gameworld during a fullscreen-video.
  5. Here the various settings are being set. playOnAwake = false; makes sure the video will not start immediately. The renderMode is set to cameraNearPlane for fullscreen-videos. The isLooping variable sets if the video should loop endlessly. frame sets the start-frame of the video. With a larger number it would start at that point (although the number should be within the actual length of the videoclip). targetCameraAlpha sets how “transparent” the fullScreen-video is going to be. 1F means it will not fully visible, 0.5F would be 50% visible.
  6. The video begins playing.

Enabling User Interaction

But you are not done yet, as these functions will not call themselves.

Open the WorldUIElement.cs file. It is assigned to the buttons you see in the level, and can be set to be a certain type of button (in this case ButtonTypes.playFullScreenOfflineVideo). In order to call the VideoController class and start the video add these lines to the start of Interact().

if (buttonType == ButtonTypes.playFullScreenOfflineVideo)
{
    videoController.PlayFullScreenOfflineVideo();
}

The entire function should look like this:

public void Interact()
{
    if (!isActivated)
    {
        if (buttonType == ButtonTypes.playFullScreenOfflineVideo)
        {
            videoController.PlayFullScreenOfflineVideo();
        }

        isActivated = true;
        displayMesh.transform.localPosition = buttonPressedPosition;
        audioSource.PlayOneShot(buttonSound);
        thisRenderer.material = materialNormal;
        StartCoroutine(DeactivateButton());
    }
}

The important part is that now that PlayFullScreenOfflineVideo() is called, and a video will play when you press the Offline Video button on the console! The rest of the code handles the button animating, and does not need to be modified by you.

Try it out and press the Offline Video button! The result should look something like this for about six seconds:

Exiting the Cutscene

You cannot quit the cutscene yet. To do that you’ll need this code inside Update() of the VideoController class:

void Update()
{
    //1
    if (fullScreenVideoPlayer && fullScreenVideoPlayer.isPlaying)
    {
        //2
        if (Input.GetKey(KeyCode.Escape))
        {
            //3
            fullScreenVideoPlayer.Stop();
            firstPersonInteractor.SetImmobile(false);
        }
    }
}

Here is what the code does:

  1. This checks if a full-screen video is currently playing.
  2. This code executes when you press the escape-key.
  3. This will stop the video and make your character be able to move again.

Once the video has finished press the escape-key to quit the video-view.

Well done, you created your very own first full-screen cutscene! Now you can get some actors together and create your own Command & Conquer-esque masterpiece. ;]

Note: When using a local file you need to adapt its filepath to the current save-location. The editor-filepath will no longer work when deployed. Luckily you can solve this by prefixing Application.dataPath to the filepath. This has already been happening in Start():

private string videoFilePath = "/RW/Videos/ForestFlyover.webm";
void Start()
{
    videoFilePath = Application.dataPath + videoFilePath;
}

Adding the Video Player Component Manually

After watching the video pause the gameplay and take a look at the main camera in the inspector. This is what you should see:

Here are all the variables that you set via code. It is also possible to manually add the Video Player component by selecting the needed GameObject, and then selecting Component ▸ Video ▸ Video Player. Afterwards only a call to the Video Player and Play() is necessary to start a video.

Note: There are some limitations on what kind of files you can use. Depending on the system you use Unity’s file import will not work for certain formats. More information and details can are available here. For example a wmv-file will only work on windows, and no other platform. Unity can import the webm-format on the other hand without issue on any platoform.

The next thing to keep in mind is that not every video file (even if the import works) will run on every mobile device, as only certain codecs run on Android devices or iPhones. More details on that are on this page.

Be sure to chose a format and codec that works on the platforms you intend to deploy too!

Playing Online Videos

Your astute eyes probably noticed the second, still not functional button labelled Online Video.

Right now the Video Player uses a locally saved file, which has been hard-coded. Alternatively you can also use a hyperlink and use an online source! To make it work add this method to the VideoController class:

public void PlayFullScreenOnlineVideo()
{
    StartFullScreenVideo(videoURL);
}

What this does is call StartFullScreenVideo, which you used before, but with the video-url as parameter.

You will also need to adapt Interact() in the WorldUIElement class with this code:

if (buttonType == ButtonTypes.playFullScreenOnlineVideo)
{
    videoController.PlayFullScreenOnlineVideo();
}

When you press the Online Video button inside the game this will call the VideoController, and PlayFullScreenOnlineVideo(), which you just added.

The video will play the same, try it out!

Setting Your own Online Source

Right now an online video has already been selected for you to use:

private string videoURL = "https://www.videvo.net/videvo_files/converted/2016_01/preview/Forest_15_3b_Videvo.mov47209.webm";

You can find this variable and swap out the link for your own favorite YouTube-video, and that video (assuming you have a working internet-connection) will play once you hit the Online Video button in the gameworld.

This offers lots of possibilities in regards to game-design, where you could possibly create a game which has a new video every time, or you could host your tutorial-video on the web, and then change the video without having to update the game itself.

Creating a Fancy & Interactive In-Game Video Screen

Open the scene 02VideoPlayer. it is very similar to the first one, only that this one has a an actual video-screen inside the world, and new buttons.

Like before the buttons don’t do anything right now. In order to have a video displayed on the big screen first add this variable to the VideoController class:

public VideoPlayer displayVideoPlayer;

This is where the script will access the Video Player. Next assign the DisplayMesh of the VideoDisplayScreen object to this variable. If you look the the DisplayMesh in the inspector you’ll see that it already has a Video Player component attached to it.

Next add this method to the VideoController:

public void PlayInWorldVideo()
{
    //1
    if (!displayVideoIsPaused) {
        //2
        displayVideoPlayer.playOnAwake = false;
        displayVideoPlayer.renderMode =
            UnityEngine.Video.VideoRenderMode.MaterialOverride;
        displayVideoPlayer.url = videoFilePath;
        displayVideoPlayer.frame = 0;
        displayVideoPlayer.isLooping = true;
    }

    //3
    displayVideoPlayer.Play();
    //4
    displayVideoIsPaused = false;
}

As before you will need this check in Interact() in the WorldUIElement class:

if (buttonType == ButtonTypes.playInWorldVideo)
{
    videoController.PlayInWorldVideo();
}

This is what happens when the code runs:

  1. It checks if the video is currently already running and paused, or not running at all. If the video has not started yet the Video Player settings are set again, as in the previous example.
  2. The most important setting is displayVideoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;, which makes the video play on the object it’s on, and not in full-screen.
  3. The video starts.
  4. The displayVideoIsPaused variable is set to false. This will be more important for using the pause-feature.

Try it out! When you press the Play button on the console the video will now run on the screen.

Adding Pause and Stop Buttons

Next up is the Pause Button, which will pause the video, if it is playing. Add this method to the script:

public void PauseInWorldVideo()
{
    //1
    if (displayVideoIsPaused)
    {
        //2
        displayVideoPlayer.Play();
        displayVideoIsPaused = false;
    }
    else
    {
        //3
        displayVideoPlayer.Pause();
        displayVideoIsPaused = true;
    }
}
  1. The script checks if the video is currently paused.
  2. If yes, the video continues, and the displayVideoIsPaused variable is set to false. This affects the usage of the Play and Pause buttons.
  3. If no, the video is paused, and the displayVideoIsPaused variable is set to true.

Next add this method to stop video-playback:

public void StopInWorldVideo()
{
    //1
    displayVideoPlayer.Stop();
    //2
    displayVideoIsPaused = false;
}

Adapt the Interact method of the WorldUIElement class with these checks to make it all work again:

if (buttonType == ButtonTypes.pauseInWorldVideo)
{
    videoController.PauseInWorldVideo();
}
else if (buttonType == ButtonTypes.stopInWorldVideo)
{
    videoController.StopInWorldVideo();
}

The Interact method should have all five checks now. You can also turn these into a single if-else block, instead of multiple ones:

if (buttonType == ButtonTypes.playFullScreenOnlineVideo)
{
    videoController.PlayFullScreenOnlineVideo();
}
else if (buttonType == ButtonTypes.playFullScreenOfflineVideo)
{
    videoController.PlayFullScreenOfflineVideo();
}
else if (buttonType == ButtonTypes.playInWorldVideo)
{
    videoController.PlayInWorldVideo();
}
else if (buttonType == ButtonTypes.pauseInWorldVideo)
{
    videoController.PauseInWorldVideo();
}
else if (buttonType == ButtonTypes.stopInWorldVideo)
{
    videoController.StopInWorldVideo();
}

Here is what happens in the new functions:

  1. The video stops. This is different from pausing as it cannot continue from its current position.
  2. The displayVideoIsPaused variable is set to false.

Now you have a simple and working in-game video player! You can start, pause, and stop the playback of videos. But you can go one step further.

Adding a Timer

See the text-display over the video-screen?

This is where you can add a timer-display. Start by adding this variable to the scrip, which will hold the 3d text mesh:

public TextMesh timeDisplay;

And assign the TimeDisplay object from the hierarchy onto it.

Then add DisplayTime:

private void DisplayTime()
{
    //1
    string minutes = Mathf.Floor ((int)displayVideoPlayer.time / 60).ToString ("00");
    string seconds = ((int)displayVideoPlayer.time % 60).ToString ("00");
    string lengthMinutes = Mathf.Floor ((int)displayVideoPlayer.clip.length / 60).
        ToString ("00");
    string lengthSeconds = ((int)displayVideoPlayer.clip.length % 60).
        ToString ("00");
    //2
    timeDisplay.text = minutes + ":" + seconds + " / " + lengthMinutes + ":" +
        lengthSeconds;
}

This is what each part does:

  1. This calculates the elapsed time of the video into minutes and seconds.
  2. This assign the minute and second values to the text in a minutes:seconds format.

Also add this code to Update():

//1
if (displayVideoPlayer && timeDisplay)
{
    DisplayTime();
}
  1. This makes sure DisplayTime() only executes when both an in-game video display object and a time display exist.

Try it out! Your video-screen will now display the elapsed time.

Importing Videos with Transparency into Unity

You can also use videos with a built-in alpha channel! A lot of stock-video sites like Videvo offer these. Sadly only certain video-types and codecs are supported. On Mac you use .mov files, and on both platforms .webm. The full details can be read on the page for Video Transparency in the Unity Reference Manual.

Note: It’s possible to transform videos with transparency that aren’t .mov or .webm files, but it can be a bit tricky, but here is the highly abbreviated version:

First you need the tool FFmpeg. Navigate to the folder where the file ffmpeg is stored (ffmpeg ▸ bin on Windows, on Mac you just get the file without any others) in you command-line-terminal. Also make sure the file you want to transform is in there too. Then run this command: ./ffmpeg -i ORIGINAL_FILE_NAME.mov -c:v libvpx -pix_fmt yuva420p -auto-alt-ref 0 NEW_FILE_NAME.webm.

This should create a new file with the necessary encoding.

Luckily there is already a video with transparency available in your project-files, and it’s called ColorHeartsTrasparent.

Correctly Tweaking Everything so that Transparency Actually Works

In addition to the Video Player you also need a custom Render Texture on the object that will be made transparent. Take the TransparentVideo material and assign it to the DisplayMesh object.

Then set the videoFilePath in the VideoController from

private string videoFilePath = "/RW/Videos/ForestFlyover.webm";

to

private string videoFilePath = "/RW/Videos/ColorHeartsTransparent.webm";

so that the correct (transparent) video will play, and not the previous Forest Flyover.

This is how the Video Player should look like in the inspector:

And if you try it out it should look like this! :)

Note: There are also some videos with a green background that could be potentially be chroma-keyed out, like the wonderful, free-to-use Van Damme Action Video Set.

That way you could replace the green parts with transparency. There are some advanced shaders out there on the web, but they are a bit tricky to use. If you find a good solution post it in the comments below!

Displaying a 360° Virtual Reality Video

Another cool thing you can do is implement 360°-videos in your games. A 360°-video is a video created with a special camera (often a series of cameras attached to each other to record an entire sphere of action). You can then watch it by turning your VR-headset (or even your cellphone!) to see all different parts of it. You possibly have seen these already on YouTube and Facebook, which already integrate 360°-videos. If you haven’t yet check out the VR category on Youtube!

The Inverted Sphere

These videos play like the in-game videos you saw before, but on an inverted sphere instead of a flat plane. You can imagine it like a regular ball that you can already create in Unity by clicking Game Object ▸ 3D Object ▸ Sphere, but with the outside facing inwards. If you now add a Video Player and a 360°-video it will get displayed on it, and if your point of view is inside it will be as if you are inside it!

Luckily there is already an inverted sphere present in the last scene, 03SphericalVideo. Open it and check it out!

If you press play you can see the sphere from the inside, without a video playing. You cannot move outside the sphere, something that is important to not break immersion in this scenario.

If you look the sphere from inside the editor you can see that the surface is inside, i.e. you can see the sphere from being within it, but not the outside. The same thing happens when you glitch into a wall in a game and you cannot see the wall you are in from the backside.

Adding the Virtual Reality Video

In order to show a video on the sphere create a new script and name it EnvironmentalVideo.cs. Add it to the inverted sphere, and add this code to it:

public class EnvironmentalVideo : MonoBehaviour
{
    //1
    public GameObject displayMesh;
    //2
    public string videoFilePath = "/RW/Videos/HundraKnektarsMarsch.webm";

    void Start()
    {
        //3
        videoFilePath = Application.dataPath + videoFilePath;

        //4
        var videoPlayer = displayMesh.AddComponent();
        videoPlayer.url = videoFilePath;

        videoPlayer.isLooping = true;
        videoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
        videoPlayer.targetMaterialRenderer = GetComponent();
        videoPlayer.frame = 0;

        //5
        videoPlayer.Play();
    }
}
  1. This is the 3d-mesh the video will play on.
  2. Here is the local filepath for the 360° video in relation to the assets
  3. Filepath-adaptation with Application.dataPath so that it also works in a deployed build
  4. Setting the Video Player preferences. In this case you want the video to loop.
  5. The video starts.

Then do not forget to assign the sphere-mesh to the displayMesh variable.

Note: Sadly implementing VR-videos directly from YouTube does not work, which is why you need to use a local file here. If you can find a good 360° file you can still implement it. The stock video site Videvo and Wikipedia have a few good ones you can experiment with!

Try it out! If you press play you should be inside the video-sphere.

Note: You can create you own Virtual-Reality game or app by looking into the Google Cardboard SDK for Unity, which comes with its own premade first-person VR-Controller! If you add it to this scene and deploy it to your phone (or even better if you have your own inexpensive Google Cardboard VR Headset) you can point and look in any direction.

Note: It is technically possible to sync events in your game to the framerate of a video, but this can have unforeseen repercussions. Synchronized events that work with regular videos might possibly not work in 360°-videos.

Enjoyment in Virtual Reality especially is tied to a smooth framerate, otherwise lags and skips will destroy the presence of the player, and cause VR-sickness. In these cases make sure beforehand that synchronization would work.

Where to Go From Here

You can download the final project here, or at the top of this tutorial.

And you learned how to implement videos into Unity, nice work!

There are multiple ways to now use these features in a game. You could go the established way and use it for cutscenes and other videos, like credits. Or you could implement in-game video-players, which display what you recorded before. If you implement video-recording you can show the last ten seconds in an instant-replay, which is perfect for local multiplayer games like Worms.

-Matthias

Video Sources

Flying Over Forest 3 (Royalty Free Licence, Videvo)
Hundra knektars marsch på Forum Vulgaris (Creative Commons Attribution-Share Alike 4.0 International Licence, Jan Ainali)

Wang Paths

This is from a while back, when I finally figured out to make adaptive path-tiles for City-Builder path placement! The 3d-models attached to the paths adapt depending on neighboring ones, making it possible to make nice, rounded paths.

This is the algorithm I scribbled down for it.. Learned afterwards this is called Wang Tiles :)

-Matthias

Building Levels in Unity – Part 1 of 3

This article was originally posted on paladinstudios.com

Hi! I’m Matthias Zarzecki, and I’m making the levels Looking For Group – The Fork Of Truth (among other things).

In this series we’re going to use Unity to create a game environment. The first part will deal with the basic landscape – the terrain on which the rest of the environment is built.

If you’ve seen our rockin’ trailer or kickstarter video (both now sadly no longer online) you can see the environment the characters fight in.

To make these videos, we set out to actually built a playable level. It serves as a prototyping area, to test the combat system and overall look-and-feel of the game. We wanted to use actual footage for the Kickstarter videos, so people would know what to expect. Ultimately this resulted in a fully functional game (albeit a rather short one).

Level overview

The gang starts in the lower right, they break into a village and get in the way of a goblin attack. Then they get a quest from a farmer (actually a goblin in disguise), and track down the goblin menace. They are lured into a trap, resulting in the final battle in the goblin camp:

The level takes about 10-20 minutes to play through, and is quite fun. So let’s talk about how we made this!

Terrain

The entire level uses the Unity Terrain. It is a great way to create natural landscapes.

To get started with Unity Terrain, select “Terrain” -> “Create Terrain” in the menu bar. You start with a flat plane:
Unity Terrain lets you “paint” on this surface, using different brushes and sizes:
Using the Height painting tool (the first mode), you can paint height differences. Simply select the right mode, and paint your terrain on the plane in the Unity viewport:
Using the texture painting tool, it is possible to apply textures to the terrain.
Start with a base texture like grass or dirt, and take it from there:
Add extra textures to create rocks, sand, any type of ground you need:
Roads are easy to create. Simply paint a specific height, and assign a road texture to the terrain:
These are the textures we used for The Fork of Truth:
2013-07-05_1437
With these simple tools, you can create complex terrains that are convincing and interesting to look at. You can see the road texture painted on the right, and the height differences in the pool:
Unity Terrain is an awesome feature, and offers a wide array of options and ways to create a world. You can sculpt almost any kind of landscape with it. Create streets, rivers, canyons – all with a swipe of the mouse.

Verticality

But you have to be careful not to overdo it. Things may look great, but a hilly terrain could give you all kinds of level design headaches.

Height differences make placing things a chore. You might end up spending hours adjusting the vertical position of the objects in the scene, so that they don’t float in the air or are stuck in the ground.

The basis for the LFG-game is a flat plane. There are still hills and depressions, but these are purely visual. You can’t actually reach them. You can see some of these non-flat areas highlighted in the picture below. They are inaccessible due to obstacles and invisible walls:

Another benefit of keeping your level flat is simpler attacks. Attacks and abilities become much more complicated when there is an uneven terrain. Does a summoned tornado move horizontally, or does it move along with the floor? If so, could it move up a cliff? If you are standing on a hill, does your fireball hit the enemies below or do they fly over? What about if there is a hill between you and the enemy?

Keeping the level “flat” gently sidesteps these problems. Games like Diablo, Torchlight and Magicka use a mostly planar environment as well. And with good reason.

Note that even though we kept the walkable areas flat, we did add uneven ground in some places to give the impression of depth. For the extended game we plan on using height in the levels. Height-differences and cliffs make for interesting level design, so we don’t want to leave it out for the real thing.

Water

The characters can’t interact with water in The Fork Of Truth (yet). Should anything fall into the water anyway, like a goblin thrown by an attack, it is killed immediately.

The river in the level is a depression in the terrain, moving down to 30 units below the “floor-level”. Here you can see the river “canyon”, with some decorative objects placed within. All it needs is a bit of water:

There are different options for the water surface. The simplest version is a simple flat square with a  blue color and transparency:

 

Unity comes with several water shaders. This is the basic one. It has animated waves and simple reflection, but no transparency:

This one is a more advanced version (the coloring is a bit off at the moment). It is transparent, and has all of the wave-animations of the previous one:

The next one is just about perfect (it is called “Water4” in Unity Pro). It is transparent, reflects the environment, has animated waves, and nicely fits the cartoony visuals of the game. It also has an interesting “fizzle” area at the borders. Even though it has all of this great stuff, it doesn’t kill the framerate like some of the other advanced water types.

Conclusion

The level building process in Unity starts with the general terrain layout. Here is a summary of the tips:

  • Use the Unity Terrain for fast landscape sculpting and texturing
  • Keep the walkable paths flat for easier level design
  • Unity has several great water shaders, we used the Pro shader “Water4”

Running around in an essentially empty level with just the ground and water beneath your feet can still be satisfying. If that is indeed the case, you have built a solid foundation for the rest of the level.  

Next time: We’ll have a look at placing the objects in the level, and fill up the environment with trees, bushes, fences, and other doodads.

Curious about the The Fork of Truth? We are running a crowdfunding campaign on Kickstarter. Check it out, and if you like what you see, be sure to back the project and spread the word!

Thanks,
Matthias

Unity and the Android Manifest file

Hey guys!

A few days ago I was finally able to port Unstoppaball DX and Vertical Void DX to Android. Reception has been good so far, and I’m glad it worked out :)

Porting and putting the games onto the GooglePlay-store was relatively straightforward. At least until I encountered this:

That is an all-encompassing list of ALL Android-devices (currently numbering 2414). Before publishing your app on the Store you have to manually check/uncheck whether each of these is supported or not. After all, any of these devices can access the GooglePlay-store (as far I can tell), and following that, any would be able to download your game.

Due to the sheer number of devices, testing all of them is ridiculously infeasible. Hell, even going through the list is infeasible. There MUST be a better way. Like “filter all devices without this feature”. That sounds doable.

So while researching a workaround I stumbled upon the Android-Manifest-File. This magical document lets you specify certain requirements of your app, like “Only run of devices with a camera”, or “only run on devices with an Accelerometer”. That’s sounds perfect.

…but unfortunately there was no documentation on how to use it with Unity. Where do I put that file? How does it look like? Where do I find it, assuming it is already present somewhere? No encompassing documentation is available for this problem. So I decided to write my own.

 

The AndroidManifest.xml-file

This “issue” pops up when you want to put your Unity-based Android-game onto the GooglePlay-store. I am assuming you have succeeded so far in building and testing your application, and just want to specify the store-requirements in the Manifest-file. Here’s how it works:

  • Build your application.
  • Luckily Unity creates a Manifest-File automatically. Go to the folder YourUnityProject/Temp/StagingArea. You will a file named “AndroidManifest.xml”. This is the one we are looking for.
  • In the Asset-Folder of your project (YourUnityProject/Assets) create a folder called “Plugins”. In that folder, create a folder called “Android”. Copy the AndroidManifest-file in there. It should look like this:

  • You can now modify the file from within Unity. If you open it, it looks something like this:

  • Near the end of the file, after the /application-tag, are the lines that specify which features are required by the app. Find them.

  • A typical line looks like this:
  • To make sure it works correctly, add the line
    android:required=”true”

before the “/>” at the end. it should now look like this:

< uses-feature android:name="android.hardware.sensor.accelerometer"

android:required=”true” />

  • All the “hardware” features of your app are automatically listed in the manifest-file near the end. By adding android:required=”true” you make sure that only devices with this features can download and install this app.
  • If you add android:required=”false” on the other hand, devices without said feature can access it anyway (but get a warning that the app would access it, if it could). This is useful for apps where motion-controls (for example) are available, but not required.

The full list of settings is on the Android-Developer-Site.

Q: What happens if I don’t add “android:required=”true”” to a specific line?
The GooglePlay-store will assume that that feature is required.

Q: So all this stuff happens on its own? I don’t really have to do this entire procedure?
It appears so. The file is generated and included automatically.

Q: Then why are you writing this?
So all this information is in one place, which until now it wasn’t. Also I’m a nice person.

-Matthias

Thoughts on My Little Planetoid

Last weekend I competed in Ludum Dare and created My Little Planetoid in 48 hours. Read on to find out what I thought afterwards (a post-mortem, if you will).

What went right

Genre/Setting
This is both a science-fiction and city-builder game. The combination itself is rather rare.

Building stuff
It just feels awesome. And I love the “Build now on moon”-gag, which I think is quite good game-design.

Timelapse
According to people this video is “intense”. It might be due to the orchestral music, but probably because my facial expressions during Ludum Dare alternates between “frown” and “manic laughter”.

Soundtrack
I composed this over the course of the 24 hours. The first idea of the music I had immediately after I decided on the idea, and it grew from there. It has been quite well received, with many people saying they like it and find it relaxing.

Also, the idea of a space-banjo is just awesome.

Graphics
Having empty space as background meant I was able to concentrate more on the 3d-models in the foreground. And while they could be improved a lot, you’ll notice there’s a lot of detail to be found.

Mood
The combination of the sombre soundtrack and the space-y visuals worked quite well, which people also remarked positively.

What went alright

Theme
This time I actually prepared. I made a list of ideas for every possible theme. Tiny World was the one where I didn’t have anything brilliant ready, so threw in an idea I already had before. After the announcement I developed more of them, but threw them out when I saw others made them first.

Scope in fiction
My Little Planetoid has a somewhat weird range of buildings. You start out with houses and farms, which could position this game anywhere in the past or future. Then you quickly advance to Science-Laboratories and advanced-space-stations. So while it is a progression through technology, I feel it could’ve been more focused.

Scope in design
In design-terms My Little Planetoid is huge.  It has more unique features/elements than any of my previous games. It has multiple complex 3d-models. It has a somewhat extensive GUI. And, most importantly, a huge web of each other influencing resources and variables.

I was even glad when something emergent happened, but there was lot of potential for bugs and unforeseen combinations. Which led to…

Balancing & bug-testing
I literally coded in something 10 minutes before the deadline. There was no time left for dedicated balancing and bug-hunting, only what I noticed during test-plays myself. The resource-balancing now kinda works, but it does feel off sometimes.

In the end the basic resources become abundant, so you aren’t really thinking about them any longer.

Textures
I used a basic pixelated diffuse-map on all things. Sadly there was no time to take care of UV-maps, but it doesn’t really show unless you really look.

What went wrong

Failure to realize how bloody huge this project is
This led to a (frankly mental) development-speed in the last hours, and the incomplete balancing.

All in all

This was an awesome and fun gamejam. My Little Planetoid is right now one of the most-played games, and people really enjoy it. The general consensus is that this could be huge if further developed. And so I will :P

Play | LD-page | Mini-Review (at 9:50) | Review

-Matthew

In a flash

So I made a flash-game with Unity for the Flash in a Flash-contest.

The flash-build-feature is new in Unity 3.5, which is currently in beta. As the number of flash-players vastly outnumber the unity-players, this is an important issue. And while not all features are enabled, it’s a step in the right direction.

in Rubidium you control the flow and reactions of the elements, so that they can undergo reactions and reach their destinations.


Give it a try.

-Matthew

Steampunk Axebots!

So Ludum Dare 20 is currently on.

It’s a game-design-challenge to create a game in 48 hours to a given theme. The theme is “It’s dangerous to go alone! Take this!”

I made a game about Steampunk Axebots. They are on their way to destroy the evil Prof. Malevolent, but they will fail, if you do not supply them with repair-kits. By piloting rockets into them.

It’s fun. Go have a try. (or see the entry on Ludum Dare here)


-Matthew