Gábor's Site
  • Home
  • Contact
  • Nibbles
    • Nibble Work-in-Progress 22/05/14
    • Nibble Work-in-Progress 24/05/14
    • Nibbles Work-in-Progress 18/06/14 - Camera Moves
  • Blog

Update of last 3 and half years

1/31/2018

0 Comments

 
Okay, so I haven't been updating for quite some time. But a lot has been achieved!
  • We have moved from Ireland to Italy. I do not speak Italian very well, but we managed to settle in, and I'm working as a software engineer (what else) in Verona.
  • I have founded a company! COR-GEEKS Software is at your service, making games.
  • I have released Nibbles! Under the disguise of Snake Supreme :).
I will try to make some further updates in the future, mostly game projects updates.
0 Comments

Nibbles Under the Hood - Edge Guide

8/10/2014

1 Comment

 
Word Cup is over, Scala course on Coursera course finished, time to get to work and extend Nibbles!
One of my good friend told me that it was difficult to navigate around on a map of Nibbles, because he didn't know the layout. Naturally I knew it already, so I didn't notice it. (That was when I realized I must use outside testers a lot! Thanks, David!)
I came up with two features to handle this problem:
  • Adding a zoom function, so you can see more ahead
  • Adding 'edge guides' to dynamic elements (collectibles) to the scene
I also fine-tuned the camera options a little bit, now it follows the snake more tightly, but I think both of the above mentioned features will be necessary. I've finished with the 'Edge Guide' feature, so let's see how it was done!
First, let me lay out my idea:
The whole concept was coming from FreeSpace – The Great War, and Skyrim. Let's take a look at FreeSpace first:

FreeSpace
Can you see the green and white thingies on the top of the screen? They follow around the edge any important out-of-sight object (targeted ship, incoming missiles), marking their direction (you have to face your ship that way to center the object), distance (the number), and also your angle to the target (the wider the guide, the more you have to turn to face the target). Pretty handy.
Next, let's see a screenshot from Skyrim:
Picture
Can you see the markers on the top? No, you can't. Let me zoom in for you:
Picture
This is a navigation bar. It marks the direction of important locations for you, and works as a compass. (You can see the 'N' for North). The locations are marked with their own symbol, but my favorite thing was that the closer you were to a location, the bigger and less transparent the symbols were! (You can compare the the turkoise and the leftmost grey arrow-thingy.)
Getting ideas from both concepts, I came up with the following design:
  • I need a component so an edge guide appears for the given game object
  • The edge guide appears on the edge of the screen, but on the inside, so it is visible by the player
  • The edge guide is positioned on the line connecting the object and the center of the main camera (to give the exact direction)
  • The edge guide is invisible if the object itself is visible
  • The edge has two components: and arrow like part, that is always poiniting to the target, and it is closer to the edge; and a symbol part, which is a visual guide of the nature of the object (typically the picture of the object itself)
  • The symbol part does not rotate, it is always right-side-up
  • The arrow part rotates, and always pointing to the object
  • the symbol part is always behind the arrow part, closer to the center of the screen
  • the further away the object is, the smaller and more transparent the edge guide is (both arrow and symbol), but only if it's possible to implement (SPOILER ALERT: it is)
Something like this:
Picture
Let's see how can we implement this.
First, let's notice, that the whole edge guide is rotating around the tip of the arrow. The symbol part however isn't rotated relative to the screen.
This gives us a structure, where the edge guide consists of two objects (an arrow and a symbol), where the symbol is the child of the arrow in the hierarchy.
So let's say the center of rotation is the red dot, and we rotate the edge guide:
Picture
Almost good, but the symbol is not okay, it needs to be rotated to the opposite way:
Picture
Perfect. Now let's fire up the Unity editor, (and Visual Studio / VS Express if you prefer), and implement it.
Let's create a new C# script, called 'EdgeGuide'. We will attach the script to our objects of interests.
The first thing we need to do is test the object if it's visible form the main camera, or not. It would seem straightforward to use MonoBehaviour.OnBecameVisible() and MonoBehaviour.OnBecameInvisible(), but it wouldn't work. The reason for that - according to this tutorial - is that these methods will take every camera into account, including the scene editor camera. So your results will be different in the editor, and in the built game.
We have to develop our own solution, which will be a shamless steal from the previously mentioned tutorial.
So every frame we test if the object is visible, hide the the edge guide if it does, or show if it doesn't. Here is our Update(...) method (called every frame):
  void Update () {
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
if (!GeometryUtility.TestPlanesAABB(planes, thisRenderer.bounds)) {
//... show edge guide
} else {
//... hide edge guide
}
}
We will use 'planes' variable later, so we save it for later. These planes are the boundaries of the visible area of the camera. Everything inside is visible, outside is not.
Let's see what happens when we want to show the edge guide.
We need to find the edge point The edge point is where the edge huide should be centered. For this, we create a 'Ray' that origins from the camera position, and points to the object itself. Then we test all the planes for this ray, and save the smallest distance:
  void Update () {
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
if (!GeometryUtility.TestPlanesAABB(planes, thisRenderer.bounds)) {
Vector3 rayOrigin = mainCamera.transform.position;
rayOrigin.z = transform.position.z;
Ray ray = new Ray(rayOrigin, transform.position - rayOrigin);
float smallestDistance = findEdgePoint(planes, ref ray);
} else {
// ... hide edge guide
}
}

private static float findEdgePoint(Plane[] borderingPlanes, ref Ray rayToTarget) {
float smallestDistance = -1.0f;
foreach (Plane plane in borderingPlanes) {
float rayDistance;
if (plane.Raycast(rayToTarget, out rayDistance)) {
if (smallestDistance < 0.0f || rayDistance < smallestDistance)
smallestDistance = rayDistance;
}
}
return smallestDistance;
}
Negative value is returned if none of the planess intersects the ray, but in our case this is impossible. We take the safe route in our code anyway.
Setting the scale of the edge guide is trivial, but setting the opacity is not. I needed some research in this matter, but in the end it turned out to be really easy. Here is the code:
  private void setOpacity(Renderer renderer, float value) {
Color color = renderer.material.color;
color.a = value;
renderer.material.color = color;
}
These are the interesting parts of the edge guide. Oh, one more thing, I've set the center of my arrow sprite to the tip of the arrow in Unity's sprite editor, so it automatically rotates around the right way:
Picture
I've uploaded the whole EdgeGuide.cs here, for anyone interested. Study or use it for whatever you like!
Happy coding!
1 Comment

No Free Time!

6/23/2014

0 Comments

 
I definately cannot update Nibbles this week.
Reason Number One is FIFA World Cup. I've implemented the camera moves during the matches, but not any more, it is not gonna work for more complex stuff.
Reason Number Two is my Scala / Functional Programming course I'm doing on Coursera. Coursera is awesome BTW. I recommend it to anyone. So my class is about to be finished, and there is one more big assigment to make, the deadline is this Sunday.
Hopefully next week will be more busy! I've decided to add Unity3D related post to this blog, whenever I finish something. This way not only you will get regular Sneak Peaks, but you can see under the hood a little bit!
See you next week!
0 Comments

New Sneak-Peak for Nibbles: Camera Moves

6/18/2014

1 Comment

 
I've implemented the camera moves: now the camera follows the snake, in a kind-of natural way. Now I can make huge maps! I've already designed a bigger one, I call it "Crosses". It has medium difficulty, and little bit bigger.
Because the camera moves now, you cannot see the whole map. Unfortunately guides for the nearest "star" are not yet implemented, you have to search for them! And as usual you will have to reload the page after the game ends. That's why it's a sneak-peak! It is not a completed game AT ALL.
The controls are the usual ones: Arrow keys and W-S-A-D are directions (or Q-C; E-Z), and ENTER or P starts and pauses the game. Enjoy it HERE, and don't forget to give feedback!
1 Comment

Balance

5/26/2014

0 Comments

 
Balancing your life can get very difficult if you work on something in your free-time.
I work as a software engineer on my day job, and I've decided to also work on my game in my free time. I basically had 3 choices:
  1. Sleep less
  2. Work less
  3. Have fun less
Let's examine these possibilities:
  1. Sleep less: if you don't want to or cannot  experiment with polyphasic sleep schedule, it is quite impossible. I recommend to always sleep enough, and be well rested. You need all your brain power. You can even exercise more: I've invested in a pair of quality running shoes, and I go run whenever I can (usually twice a week). Sittting in front of the computer is not very healthy, and exercise helps you sleep well too. Sometimes I can think about future features during run. It does worth to exercise instead of coding once or twice a week.
  2. Work less: without changing job that is quite impossible. Be respectful to your employer. But try to have a tight schedule, and don't work overtime! Now that you have your own project you need every minute. Timebox your workday. I try to be a little bit early too rather than staying later, but whatever your preference is.
  3. Have fun less: I've actually chose this one. And for me "have fun less" means "go to pub less" and "drink less". I won't have hangover, and I have more time. Friday is still "after work pub" day, but that one is kind of scheduled now. I didn't cut back on general internet browsing, and games, my other fun activities. I don't turn down occasional invitations either (barbeque, restaurant, etc...).
Very important: don't steal your time from your family, partner, or other people who you are close to (including pets). It can be very difficult, but if they understand that this project is very important to you they will understand.
Good luck!
PS.: Don't cut back on hygiene ;-)
0 Comments

Why Unity3D?

5/25/2014

0 Comments

 
If you want to create a multiplatform game, you have numerous choices.
You can create everything from scratch. That does not really feasible for a one-man team, so I won't tell more about this. I don't recommend this. I don't even recommend starting from scratch even if you aim for only one platform.
Another option is Cocos2d-x. I've tried it, it is not too bad. It is a C++ framework basically, but there are graphic tools that you can use. The main method of creating your game is through coding though. It is totally free and open-source. I think it gives great freedom, you can integrate basically anything you want, but I think the development is slower.
Unity3D is not free, but there is a free version. Some advanced features are disabled in that, but you can build to any platform even with the free version. A nice graphic interface, where you can drag-and-drop your features to the editor, and you can run your game inmediately. Once you ready to build to your platform, with a few clicks you can port to anything. Of course you have to take care of the different features for different platforms, but the entity based architecture allows you to enable and disable features with one click. (Example: I've implemented touch controls for my Nibbles game, but I can disable them with one click for the Web or Desktop build, and use the keyboard for control.)
What else would you recommend?
0 Comments

    Gábor's blog

    Some technical and personal stuff

    Archives

    January 2018
    August 2014
    June 2014
    May 2014

    Categories

    All
    Cocos2d
    Nibbles
    Personal
    Programming
    Unity

    RSS Feed

Powered by Create your own unique website with customizable templates.