May 25, 2015

How to optimize Unity and other tips and tricks as well as best practices

0 comments
This is a link roundup with articles describing how to optimize Unity as well as other tips and tricks and best practices.

Unofficial sources:
Unity3D tips and tricks. Various gif images showing tips and tricks.

"0 – 60 fps in 14 days!" What we learned trying to optimize our game using Unity3D.

50 Tips for Working with Unity.

Guidelines for using rigidbody, collider, CharacterControllerScript, etc.

What's the best way to reduce draw calls?

The top 5 things I've learned as a Unity developer.

C# memory and performance tips for Unity.

Unity Configuration Tips: Memory, Audio, and Textures.

How To Plan Optimizations with Unity.

Optimizing Unity Games.

10 things you didn't know you could do with Unity.



Official sources:
Optimizing Graphics Performance. Simple guidelines for maximizing the speed of your game’s graphical rendering.

Good coding practices in Unity. The idea behind coding practices is that you keep in mind a set of guidelines when you write your code. These guidelines are often designed to keep your code maintainable, extensible, and readable, which in turn helps reduce the pain of refactoring.

Physics best practices. Best practices for when using physics in a game and some evidence to demonstrate why they should be used.

Unite 2013 - Internal Unity Tips and Tricks [media]. Tim Cooper, developer at Unity, gives a range of tips and tricks and explains why they work in the engine. Topics include smart data structure layout, property serialization and memory and graphics debugging.

Unite 2014 - Mobile performance poor man's tips and tricks [media]. Tautvydas Ĺ˝ilys (Unity) on the most common pitfalls in perfornace how to actually know what is wrong in your game.

Unite 2014 - The Hack Spectrum: Tips, Tricks and Hacks for Unity [media]. Ryan Hipple of Schell Games shares a number of unconventional Unity tips, from polymorphic array serialization to stealing parts of the Unity editor UI.

May 24, 2015

How to create water wakes in Unity?

0 comments
The question is: How do you create water wakes in Unity? If you have ever seen a boat on a lake, you notice that it will leave small waves behind it while it is floating forward. But how do you create those waves, and how do you combine them with a moving sea in a computer environment like Unity? I've earlier made a boat that will float in Unity with realistic buoyancy, and now I felt I wanted to learn how to add water wakes. No boat is complete without them.
The answer to the question is using an algorithm called iWave. There are other alternatives, but I believe iWave is the most popular algorithm. It was first published in 2008 in a report called Simulation of Interactive Surface Waves. The report was written by Jerry Tessendorf, who is an expert in the field. If you've ever seen a computer animated sea in a movie, like the sea in Titanic, the algorithm behind the realistic moving sea was written by Jerry Tessendorf.
The algorithm itself is not that easy to understand, but the simplified version is actually very easy to implement - and it is super fast. The only expert tip I have is to change the parameter alpha if you encounter gigantic waves. The algorithm itself is not that stable, so alpha is like a damping parameter. 
My final results look like this:



You can interact with the surface with your mouse, and the small cube will float with my old buoyancy algorithm. The difference now is that the cube will leave ripples whenever it is bouncing up and down. 
Looks interesting? Don't worry, because I will soon write a tutorial on how to do it in Unity. It will be published here: Tutorial on how to make a boat in Unity.  

May 18, 2015

Book review: The Quest for Artificial Intelligence

0 comments

This weekend I've watched two movies about smart robots. The first was called Chappie and it tells the story of a robot named Chappie, who is the first robot with the ability to think and feel for himself. Chappie is therefore much smarter than any other human. The second movie, Ex Machina, is also about a smart robot with the same abilities as Chappie, although the robot in Ex Machina is looking more like a real human.
The question is how realistic are those movies? Will we soon see robots that are as smart as Chappie? To be able to answer that question, we have to take a look at the history of artificial intelligence, or AI. And that's why I read the book The Quest for Artificial Intelligence by Nils Nilsson.


The Quest for Artificial Intelligence was published in 2010, and is therefore up to date with the latest histories of artificial intelligence. But AI is a field that these days is moving fast, so some of the latest achievements are not included, such as the algorithm that learned how to play the game Breakout.
Nils Nilsson knows what he is talking about. Among other projects, he has developed the famous A* search algorithm. If you have ever played a computer game where the characters are controlled by the computer, the game is probably using the A* algorithm to help the characters find their way around the map.
The early history of AI begins hundreds of years ago when the old Greeks dreamed about self-propelled chairs. Then it continues with Leonardo da Vinci, who in 1495 sketched designs for a humanoid robot in the form of a medieval knight, and ends with a mechanical duck.
But the real history of true artificial intelligence begins after the Second World War, with a series of meetings. At these meetings, researchers described early attempts to highlight features in images and how to program a computer to play chess. The first meeting was called "Session on Learning Machines," so the word artificial intelligence was not yet invented, until someone suggested the word. Everyone were not convinced, but then most researchers began to use the name artificial intelligence. 
"So cherish the name artificial intelligence. It is a good name. Like all names of scientific fields, it will grow to become exactly what its field comes to mean."
What happened after these early meetings was that the quest for artificial intelligence began at the same times as the computers improved. But everything didn't go smoothly. Nils Nilsson has named the downs in the quest for artificial intelligence "AI winters." What happened was that governments around the world sponsored researchers to develop AI algorithms (generally for military purposes). But since AI is a difficult topic, these algorithms didn't always work.
When they didn't work, the governments decided to decrease the funding, and the researchers had to endure an AI winter with little or no money. Then the computers and algorithms improved, the governments were yet again excited, then the algorithms didn't work as promised, and another AI winter happened.
According to Nils Nilsson, what these AI winters led to was scared researchers. The naysayers around the researchers could give comments like:
"Most people working on speech recognition were acting like mad scientists and untrustworthy engineers." 
So the researchers decided to develop simple algorithms that would actually work as promised, and ignore the more complicated algorithms that didn't always work as promised. For example, the transcription of spoken sentences to their textual equivalents is now largely a solved problem. But that is not true intelligence. The computer can't still understand natural language speech (or text) so someone can have a dialog with a computer, like in the movie Her. The latter is generally called strong AI, while the former is called weak AI. So most researchers have throughout history focused on weak AI to not lose any respect. They were saying:
"AI used to be criticized for its flossiness. Now that we have made solid progress, lets us not risk losing our respectability,"
So if you are wondering why artificial intelligence is not as intelligent as in the movies Chappie, Ex Machina, and Her, the answer is that most researchers have focused on weak AI. The emphasis has been on using AI to help humans rather than to replace them. Yes, a computer can beat a human in a game of chess, but that computer is not intelligent. Deep Blue is considered to be the machine that's the best chess player in the world, but Deep Blue doesn't know that it is playing chess. 
"Does Deep Blue use artificial intelligence? The short answer is no. Earlier computer designs that tried to mimic human thinking weren't very good at it. No formula exists for intuition. ...Deep Blue relies more on computational power and a simpler search and evaluation function."
One idea here is to actually have computer chess tournaments that will admit programs only with severe limits on computation. This would concentrate attention on scientific advances. 
The last chapter in the book is called "The Quest Continues," so artificial intelligence is still far away from being a solved problem. We may have algorithms that know how to drive a car, how to paint a painting indistinguishable from true art, and how to compose music. But we are still far away from robots like Chappie.
This short text is far away from being a summary of the book The Quest for Artificial Intelligence. The 700 pages are filled with facts and anecdotes. But don't worry, even though you will need math to develop AI algorithms, the book includes some math to explain a few algorithms, but it is more a history book than a math book. So if you are interested in the history of AI, then you should read it.

May 16, 2015

How to get more data than what you already have by using data you already have

0 comments
I've read an article about Andrew Ng called Inside The Mind That Built Google Brain: On Life, Creativity, And Failure. He has earlier worked for Google and is now working for Baidu. At Baidu he's working with speech recognition. To make speech recognition work, you will need a lot of data. One clever way he found to get more data by using data he already had is:
Then one of the things we did was, if we have an audio clip of you saying something, we would take that audio clip of you and add background noise to it, like a clip recorded in a cafe. So we synthesize an audio clip of what you would sound like if you were speaking in a cafe. By synthesizing your voice against lots of backgrounds, we just multiply the amount of data that we have. We use tactics like that to create more data to feed to our machines, to feed to our rocket engines.
The rocket engine he is referring to is the speech recognition algorithm, where data is the fuel that powers the rocket.

May 12, 2015

Random Show Episode 28

0 comments
A new episode of the Random Show with Kevin Rose (founder of Digg) and Tim Ferriss (author of The 4-Hour Workweek) is out! This is episode 28.


Lessons learned
  • Kevin Rose has begun to move away from the digital world and towards the old-fashioned analog world. Tim Ferriss is following the same way, and he's often putting his phone on airplane-mode to disconnect.
  • Neither Kevin Rose nor Tim Ferriss are interested in Apple's new watch. Neither is Tim Ferriss needing an iPad. He prefers a smart-phone with a large screen and a flat keyboard he can connect to the phone. 

Recommendations
  • Tim Ferriss is experimenting with a new diet (as usual) called Ketosis. To help him, he's using a glucometer called Precision Xtra. 
  • Kevin Rose is drink a lot of coffee (and tea) and now he has bought a coffee bean-roaster, called Fresh Roast SR700. Tim Ferriss, on the other hand, has a Hario V60, which is a Japanese coffee brew method.
  • Kevin Rose has bought a new camera, a Leica M-P, which is a camera that's both digital and analog.
  • Kevin Rose recommended the the Breakaway Matcha, which is a brand of green tea, and he is also into fermenting is own food.
  • Both Tim Ferriss and Kevin Rose are using an egg-cooking-machine called Cuisinart Egg Cooker.
  • Tim Ferriss recommended the book A Wrestling Life: The Inspiring Stories of Dan Gable, which is a biography on the wrestler and coach Dan Gable.
  • The "Tim Ferriss Experiment" is out! It is a video-series where Tim Ferriss is experimenting with various skills, like shooting a gun, learning a language, and driving a rally car.

If you want to watch the rest of the episodes, you can find them here: The Random Show with Kevin Rose and Tim Ferriss.