Posts Tagged ‘coding’

The Trouble With Tiles

All of Epistory’s levels start as an isometric RPG in Tiled (as explained in this prior article). This is a great foundation to build on – but it brings some technical limitations which we have to deal with. For example, we have to respect the TiledToUnity plugin rule that each tile must be a square of equal size. It doesn’t help that any tile rotation must be done as a duplicate tile instead of a random effect.

As a result of this, the tiles use to build each level stand out too clearly. We can see the seams, the joins, the patterns. The effect is fatal to immersion within the game world.

This old screenshot illustrates the problem nicely. Each tile is the same as the previous one, creating a very obvious pattern. This is just a small example – sometimes the whole screen will have the same tile, interrupted only by the occasional prop or decoration.

In this article, I will guide you through the steps we used to break this ugly pattern and improve the overall look of the ground tiles, which currently look like the screenshot below. It’s unlikely that we will change the tile’s look again – but you never know.

Start at the Start

If it sounds obvious, it’s probably because it is! Rotating each tile will help make it look different and vary the seams created where they join.

We started by rotating our tiles randomly with an editor script. Since our goal in art direction was to create a hand-made paper world, we decided early on that a tile would be considered an independent square of paper. Based on this fact, we agreed that imperfect tiling between two tiles was acceptable: meaning that rotation gives us variation. The result was better but still a bit jarring.

Lean Towards the Abnormal

Because each tile is supposed to be a piece of paper, it’s hard (not to mention expensive) to make each one visually unique. We aimed to solve this by dynamically changing the normal map on each individual tile.

A normal map is a 2D image used to replace or modify the normals of a 3D surface. Because our tile models are mostly flat, we use normal maps and lighting to give them some paper-looking wrinkles.

Here’s how we modified our ground shader in Shader Forge:

world position.

a parameter which allow us to tweak how much a change in world position affects the overall look.

division.

frac. It takes only the fractional part of the input. Effectively producing a value from 0 to 1, based on the world position.

append allows us to create a vector 2 (UV in our case).

normal map sampling.

normal blending. You cannot blend normals the same way you blend colors so we use a custom formula.

The effect of this is that instead of having one normal map per tile and limited to its bounds, we have two normals, whose UVs will depend on their world position. This effectively spans (and repeats across) the whole level. If you look carefully you can see that one of them will have U & V depending on the positions X & Z while the other will map U & V to Z & X. This “crisscross” allows us to have very different looking tiles each time, instead of having the pattern being simply repeated less often.

If you want a more visual way of understanding this, you can see it in the editor view. We created a gif but it was too heavy to be posted inline. You can find it here.

You can see that when I move the tiles, the normal on top of it doesn’t move. The apparent seam on the normal is a result of the tile rotation around Y.

As a bonus, we also added a detail texture. It’s a common technique so I won’t explain it here – but here’s the shader forge screenshot:

Perfect Imperfections

This was the first time I did major shader work and it turned out quite well in my opinion. With the current art direction we had to improvise a bit – but we successfully fixed the tiling problem with no rework on the assets. This results in a seamless, believable game world.

Introduction

Most games can be reduced to a series of actions and reactions. Today I would like to share with you a way to facilitate iteration and expansion of these interactions. It will sound obvious to a lot of people but I would have loved to see this kind of example 6 months ago. When I was not yet used to component based mechanics.

It all started with a simple request a few months ago, we had just designed & implemented the scoring system and we needed items in the game world to be able to give points when activated. Easy, I wrote a small script which would be attached to objects that had to add points when activated. Controlled by our item’s base class, it would be called automatically.

The buildup

As time went on, that simple “points giver” script was updated to include various behaviors like prefab spawning, door unlocking and so on. It worked well but it was not very flexible. So I changed the structure to include a parent class to have a common entry point and place each behavior in a child class.

It’s not standard notation but you can see the rewards and the items have a base class, and only these base classes interact with each other. The same kind of effect could be achieved with interfaces but I prefer to have a default implementation.

The true power of this structure lies in the modularity. Every trigger or actionable item in the game works with any reward and you can place any number of reward in a game object. The most basic action/reaction you can do is simply “collider – trigger – reward”. The player walks in the scene and something happens (tutorial message, cinematic, …).The possibilities are exponential and a new reward behavior is very easy to add.

Polish & additional features

Over time, features were added. Like the possibility to set a delay between the action and the reward. Camera travelling firing rewards at event points… What started as a joke -“reward” as in skinner boxes- is becoming a running gag: we’ll call this one “reward_kill_player”.

I recently did the same kind of structure for visual effects. A few key points (creation, destruction, hit, …) are exposed via a base class. You just have to derive from it and you get all the hooks that an artist would need to handle animations or particle effects.

Conclusion

The system is currently powerful enough to allow our designer to create our whole in-game introduction & tutorial with only the reward system. Looking back my only regret is that this system was not put in place earlier to have more of the game relying on it. Also, calling it “reward” when it’s in fact a “reaction” was a bit shortsighted.

I can share some sample code if some of you are interested. I leave you with one of the more complex interaction that we can produce.

P.S.: As a very tangible reward after a long wait between news here’s a few free gifs. Both features were added this week:

- One of the first iteration. Nothing special…

- One of the last iteration. Circular pattern, grows from the middle and not all of them at once.

Discovery of what unity can do in terms of jiggly bones and overriding animations.

The inception

A while back, after slowly becoming mad tweaking animations and movement behavior on our avatar, I decided to have some simple fun with Unity. See where the limit was and what’s possible in a certain domain. Since I was obsessed with the character’s animation, my attention was driven towards improving what our animator gave us in terms of natural movement. Even though the animations were quite good, I wanted some physics madness in there. So I went on a quest to mess with the bones of mecanim.

It turns out it’s rather straightforward to activate the so called “jiggly bones”. A few changes in your model before export does the trick. It does however require a great deal of value tweaking and physics engine know-how. You may follow this tutorial if you want to try it for yourself.

Here’s what I could do as a quick ‘n dirty test. This will *not* be in the game. Even if the effect could be nice, It is at the bottomest bottom of our priorities.

But doing this as a playful “what if” helped me learn a lot about how Unity works with animations and physics. Even better, I would never have thought of what I’m about to show if I hadn’t gamed the system.

A few days later, the movement and animation finally polished, I found one last thing I could do, turn the head of the fox in the direction of where the avatar will go next. Providing a subconscious feedback on the movement. Using the head bone and overriding the animation, it should be possible. Right?

It turns out it is. This gif was taken when a bug prevented the fox to move or turn so you can clearly see that the head orientation is overridden (and a bit disturbing, sorry).

The result

Here you can see the result in game. Slowed down on purpose to make sure it’s seeable in a gif. The effect is very subtle but you can see that the head will always point to the right direction (almost instantly) and the body follows soon after.

The next time you are frustrated with a particular task or simply bored out of your mind after a day of repetitive tweaks. Do yourself a favor and just play with the tools on your workbench. Who knows what kind of gem you’ll unearth.

Paradigm Shift

When we started working on Epistory, we had to choose whether to use our proprietary engine or not. For reasons that go beyond the scope of this post we decided to go with Unity. While the prospect of working with a tool as streamlined as Unity was stimulating, after five years working in a workflow dominated by C++ my C# habits were rusty if not inexistent.

After some time with C# I remembered and saw some of the neat tricks you can do with this language. I also received and read a few tips for Unity itself that can do wonders to keep performance high and coding time low. I will keep this as code free as possible and direct you to the relevant documentation -if necessary- to get all the juicy details that would needlessly blow up the length of this post.

Stay organized

While Unity is very flexible and lets you do basically anything, it can be a blessing as well as a curse. If you don’t force yourself to organize the project and the code from the start, it will become messy really fast. One performance hit that is negligible at the beginning but can grow into a big problem later down the road is the caching of your GetComponent(). Basically each time you ask for a specific component in a GameObject, Unity will go through its component list. In most cases you can safely cache the result and keep a reference. If you start adding components at runtime you’ll have to decide whether to cache it or not.

Leave no warnings behind

Even though most programmers will treat warning as error -or at least minimize the amount of warnings- it bears repeating. The more serious warnings are almost always a bug waiting to be triggered. That is even more important in C# because of some leeway given to the developer. For example: you can hide a virtual function if you don’t explicitly add the override keyword to the sub-class function declaration. And a warning will remind you to make your intentions explicit. The difference between overriding and hiding is that the overridden function will call the runtime type and the hidden function will call the compile-time type.

False friend

The switch statement is a good way to keep the code readable. But in this case its behavior is slightly different in C#. You cannot fall through to the next case section. You have to place a break/return/goto… However, there is a walkaround. You can use something like “goto case 1;” to jump to another case. More details here

Missing Link

LINQ can be a powerful tool to interface a program seamlessly with a database. Even though its syntax can be off putting, you should at least try it before you leave it. You can use SQL-like statements to query an xml file, for example. You can also use it to perform operations on IEnumerable (a.k.a. Arrays and Array-like) classes. All you can eat buffet here

Daily routine

Coroutines can be achieved in pure C# but Unity made their use very easy and intuitive. It is akin to starting a new thread without the problems associated with thread safety issues like concurrency, race condition & deadlock. The coroutine also behaves like any other member function. It has access to other functions and member variables.

I will leave the implementation details aside (see links below) but know that it can easily be used to provide easing to an object over time or calculate the next score increment. Another, more advanced, use-case is a very elegant way to implement a state machine. More information here and there and state chartshere

Eventful delegation

Event firing and registering is built into the language. Events & delegates are two sides of the same coin. The delegate provides an equivalent to an array of function pointers and the event is the message being sent. This makes for painless event driven programming and we all know how much a game can be event heavy.

From the 8th to the 14th of December it is the Computer Science Education Week that will take place all around the world. The event will specially focus on the Hour of Code. The Hour of Code is a global movement reaching tens of millions of students in 180+ countries. Anyone, anywhere can organize an Hour of Code event.

Facts, observations and tools that could help you for the future!

We really hope that you had a wonderful weekend. Thanks to the Belgian National Day it’s was a long weekend for us and most of the team spent some quality time with their friends and families.

Back to work, we are doing our best to drain traffic on the project, which is not that easy. Here are some facts and observations about the project:

We are 15% funded.

There are still 15 days to go.

We need $2,276 per day to succeed.

Press coverage didn’t help that much (brought 10 backers – Thanks to them for the support BTW).

1/8 people that visits our page, back our game.

The solution is to get known via social networking

I am really brilliant in paper crafting!

Based on that, our action plan will remain the same. We’ll spend hours talking about Algo-Bot on social networks. If you could help (one more time) to drain traffic to the page it would be awesome. You can see the power of your network using simple tools. Here’s one of them.

If you shorten a link with https://bitly.com/ you can track the traffic on it. All you have to do is to copy-paste that shorten link on your browser, add a + at the end of it and press enter. Then, you’ll know how many people clicked on this link, when they clicked and where they are located. You can do this with any bitly-link. Here’s the one I am using for a few months now. Feel free to check its stats: https://bitly.com/1uEHxbv+

The fun part

Today, I took a few minutes to build my Algo-Bot papercraft. It was the right occasion to show to $20+ backers how to build it :)

Just an idea

We were thinking of creating collector papercrafts with other skins from the game. What do you think? The papercraft would be awesome with the Steampunk skin!

Another programming game

This guys asked me if we could cross-promote each other. After having a look at their project we immediately said YES. Here the reason why we accepted:

We support indies!

It’s a programming game.

The concept is quite interesting but needs help to get better.

They only have 31 backers for the moment but I am sure some of you would like to support the project.

This week we worked on a tool to ensure the Norn genomes will be modified like it should in case of a genome update. It means that if a game update changes the way the Norn behave, we should be able to “update” the already present Norns too. It was a bit tricky, and we still have some work to do on it.

We also worked on an improvement of the loading screen. If for some reason the game data has to be redone, it now displays the progression at the loading (before this modification, the loading bar stayed at 0% for some seconds in that case).

Also, we fixed a bug where the game looked for a pregnant male Norn model and crashed^^”.

Whenever selling objects, we now send a message to the server. In case of a server’s latency, selling an object will now be better handled.We also implemented a “stage” server, which will allow us to keep versions of a game waiting some approval before pushing the modifications for real.Also, we are working on the science kit, in which the informations are currently too clustered.

We also finished the genome patch tool I’ve mentioned last week. It covers our main progress for these last days.

The moment you’ve been waiting for has come. Algo-Bot hits Kickstarter for the second time this year and we have 24 hours to do better than the last time.

What?! 24h? But this Kickstarter will run during 30 days!

YES, that’s true but based on our observations we know that we less than 2 days to get as much backers as we can. Because Kickstarter is not about money but about backers! Backers are the key! So, every backer helps even if you back a single little dollar!

You don’t want to back our project? That’s just fine! Maybe you could share it around you and let potential backers the possibility to discover the game. Here’s a short list of what you can do to help us. Do what you want but please, do something

We are profoundly grateful to those of you who backed Algo-Bot but the Kickstarter has to be momentarily canceled for important modifications.

It stills only 10 days to go and we still haven’t reached the 10% threshold of funding . Except if by an unexpected miracle the game raises $55,000 in a week, we won’t make it. Let’s be honest, the project raises approximately 150 bucks a day. No need to tell you that it’s not enough.

A deep analysis of our project and your comments showed us that we have 2 important problems that must be solved: poor visibility on the project (especially in the US) and thecommunication of the goals of the project.

The communication

After talking with some of you and reading your comments, it appears that we have serious issues with our communication.

First of all the message is not clear, what this game exactly is? Is it a game or a learning tool? For whom this game is meant for? Is it for kids, Programmers or programming students?

For example, according to Programmers, the inner-joke headlines were funny but could scare non-programmers. It remains a problem because the game is not only meant for Programmers and can be enjoyed by puzzle lovers? See? The message should be simplified.

The visibility

The press coverage we had represents 2% of the funds we raised which is nothing compared to your shares on social networks that raised nearly 43% of it. Thank you for that by the way!

The error we made here, was to count on press coverage to bring us backers instead of counting on our Kickstarter page to bring us backers and press coverage as a result of popularity.

One says that success doesn’t have to be a goal but always a consequence.

Conclusion

That’s the reason why we decided to cancel Algo-Bot KS campaign for a few months. Just the time to re-arrange the page and make the communication clearer and we’ll be back on Kickstarter. In the meantime our Greenlight campaign goes really well and be sure to spread the word around so the game can continue its ascension.

Finally, you, our beloved backers are welcome to sign up to Algo-Bot Newsletter to keep an eye on the project. Also, if you have any idea to improve the page, let us know! Thank you again for your support!