Salomonsson.se
Mar 05 2015

2D platform engine in unity part 11 - Wall jumping

Today I made the following new features

  • Moved the project over to the newly released Unity 5
  • Played with a particle system running as part of the background
  • Started on wall jumping feature (based on public demand), this is not all done yet though!
<< Click to play >>

Moving the project over to Unity 5 went pretty painless, unless the collider offsets were messed up on my platforms, meaning I had to adjust all of them. Luckily the level isn’t that big, which meant it only took a few minutes. If I had turned the platforms into prefabs (which would have been the right thing to do) this operation would only have taken a few seconds.

And I’ve been playing with the though of adding some background particles. I wanted some slow/smooth/subtle background noise. Well… I don’t know what to think of it. I could have spent the entire night tweaking it. But instead I moved on to the wall jumping part.

I have to say I’m very satisfied with the gliding part (just need to add some particles while slowly sliding down the wall), but the actual jumping-part is horrible. But that’s something I’ll have to fix another nigth. Now it’s time for bed.

Mar 02 2015

2D platform engine in unity part 10 - Big level

Today, with the platforms finally fixed, I started expanding the level. I’m not sure how Unity optimizes what goes on behind the scenes, so the only way to figure out is to try it out. Also, it’s a good way to find out what features I feel like I’m missing. Like pick-ups, or enemies that or obstacles that will hurt you. It also gives me some room to really try out the features I already got. Like the treadmills for example.

<< Click to play >>
Mar 01 2015

2D platform engine in unity part 9 - Fixing platforms

I haven’t been coding much (on my game, that is) for the past two months. Instead I’ve spent a lot of time watching the Handmade Hero stream. It’s really fascinating and I highly recommend it, but I’ve been having some code cravings lately. So I decided to go back to my platform engine again.

Last time I coded on it I left it in a rather poor condition, with some buggy moving platforms. The problem is that the Character2dController reports to the platform that it has collided with it, and the platform keeps track of the colliding entity and reports back its change in movement to the Character2dController. But the platform only held a single instance of the colliding object, meaning it messed up if more than one entity intersected it. The problem was solved as easy as changing the variable to a list.

Something that is very useful when debugging this kind of graphical application (with several entities with different state and values) is to be able to easily read state data. For this I’ve added debug output above each Character. This debug is a stand alone component, so I could easily add it to the moving platform as well, to verify that the list of colliding GameObjects counts up and down as expected.

Apart from this bug fix there’s no new features, so I don’t provide a new build today.

Jan 15 2015

2D platform engine in unity - part 8

Last time I promised a bigger world, and starting with animations. It seems I forgot a very important feature: moving platforms!

Todays build features:

  • Moving platforms (still a bit buggy)
  • The moving platform to the left is a Solid platform, you hit your head if jumping on it from below
  • The moving platform to the right is a Cloud platform. You can jump on it from below, and jump through it with down+jump Give it a try

Known bugs (to be resolved):

  • The platform can currently only handle one colliding object. If two or more entities touch the platform very strange behaviour will occur.
  • You can fall through a platform if you fall downwards and it moves upward at larger speeds. And as a side note: I think the game looks better with Unitys debug stuff enabled. Don’t know if you can export the web player with those enabled. I think not… Next time: Platform bug fixes and then performance on big worlds and animations.
Dec 29 2014

custom 2D physics in unity - part 7

First of all, a disclaimer: I have decided to change the name from physics to platform engine from this point. Not sure how much more physics I will implement right now. I think from now on it’s time to focus more on trying to make this into something playable.

Todays build features the following:

  • Bugfix for Treadmills reaction to player
  • FPS Counter (in top left corner)
  • Xbox 360 Controller support (at least on Windows), not sure if it works in web player…
  • NPC:s with same physics component as player. Very simple AI controller

Give it a try

Finally the work started to pay off with decoupled physics. The input is also decoupled, meaning that I could just duplicate the player logic, remove the input script and attach a simple AI controller instead. Now we have a whole bunch of red NPC:s running and jumping around.

I think next step might be to build a larger world to be able to see if performance is doing ok in a larger setting. Otherwise I think that it’s time to start looking into graphics and animations.

Dec 27 2014

custom 2D physics in unity - part 6

Try the current build

News in this build:

  • Refactored character controller system (more on that below)
  • Jump button is now space bar instead of up arrow (conflicted with ladders)
  • Disable gravity while on ladders (was buggy before)
  • Cloud platforms are disabled while climbing ladders (can climb down through them)
  • Down+Jump while standing on a cloud platform and you jump down through it
  • Removed that silly fist

Been some while since I last wrote now. Been doing some other stuff than Unity (some c++, and some updates to Ripple and its level editor). But now it’s time to get back to this little project again.

Something that bothered me a lot in the past was how fast it gets messy when implementing platform mechanics. You need need to keep track of if you are jumping, falling, standing on ground, climbing, ducking, sliding, hurting, attacking. And these states gets intertwined into each other. For example: what is a valid state for a charater to jump? He should be standing on the ground – unless if he’s climbing a ladder… or if he’s hurt or dead. And if the player pressed the jump button and the character lands on the ground without releasing the button then we shouldn’t automatically jump again until the button is released and pressed again.

My very small piece of code had already started to get messy this early on, so for a few days I’ve been refactoring it into smaller, more independant and stand-alone modules. This new version is completely rewritten, and all the previous functionality has been ported. Along with a lot of bugfixes. Still the physics feels a little weird, so some more tweaking is needed. I guess next step is to implement some simple enemies with the same character controller…

Nov 03 2014

custom 2D physics in unity - part 5

Late and tired tonight as well. Just a very short, and very unserious session tonight. Been thinking about using Adobe Kuler (seems to have been rebranded to Adobe Color CC) to get a better palette of colors to use when working with programmer art as I currently do. The result wasn’t very impressive so I guess it needs a little bit more tweaking. I also added a punching fist a la Alex Kidd, but the player doesn’t have anything to hit yet. And the ladders are still broken (will fix that in my next session).

Here’s a short demo of the punching fist

Oct 30 2014

custom 2D physics in unity - part 4

Started on ladders today. But it’s late and I’m really tired so I’ll have to continue some other night. Still happy with the result so far though! This will be awesome once I’ve tweaked it enough.

Try my ladder here

Oh, and by the way: the source code for this can be found here in case you wonder how I did stuff: https://github.com/Tommislav/unity2dPhysics

Oct 29 2014

custom 2D physics in unity - part 3

Been a while since last time I sat with this, but tonight I managed to get cloud platforms working.

So right now I have: Solid blocks, Cloud blocks and Treadmills. Next up: Ladders and Elevators! Planned after that (maybe): Gravity shift. Perhaps slopes… not sure yet.

Try it yourself!!!

Oct 20 2014

custom 2D physics in unity - part 2

Not much to see here yet… still working with boxes

Been working a bit here and there on tweaking the scripts to the way I prefer them. Not really getting any visual progress, more just shuffling code around.

Takes some time since I’m not used to how to work with Unity. I know on a conceptual level how I want my code to work. But it’s starting to feel nice. Soon time to add treadmill-colliders =D

Oct 14 2014

custom 2D physics in unity - part 1

I have found a fantastic tutorial series on 2d in Unity which can be found here (it’s several hours in length). Not only do they build a complete game (instead of the usual one-screen-tutorials most others do), they also tackle complex subjects such as slopes and moving platforms. And they do it with really beautiful code! It’s very obvious that the programmer is extremely talanted. He manages to keep the code very clean and readable, and keep the abstraction levels very well separated. This is one of the best game programming tutorials I’ve seen in a very long time! I highly recommend it!

And after watching through it I started writing my own custom 2d physics. Why? Because I don’t like the built in for 2d games. You cannot do obvious things such as cloud tile collisions for example.

<< Click to play >> (move with arrow keys, press shift to move faster)

Oct 01 2014

pixel perfect tiles in unity

I was wrestling a bit with how to get my tiles 1:1-scale. Turns out this is the way to go:

  • Set camera to orthographic (2d), and set the size to screen height/2. Since I optimize for PS Vita screen (960×544) that’s 272.

  • Now the tiles are super tiny. That’s because I created the vertexes with 1 unit as spacing. My tiles are 64×64 so I can either re-write all my vertexes (multiply them with 64). OR we can keep the 1-unit vertexes and divide the camera size (272/64 = 4.25)

Bingo! Will probably cause some problem when I have to move my sprites by 1/64 per pixel… That’s future Tommy’s problem though =) Oh, and if you have a dynamic size of your screen you can use Screen.height;

Edit (2016-12-14): here is a good blog post from Unity about pixel perfect 2d in Unity: https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

Sep 30 2014

drawing a custom 2D tilemap

I have a really simple/stupid demo today. It is however a little bit more awesome behind the scenes as I render the tiles to a mesh programatiacally in Unity. I used most of the stuff from this really awesome tutorial http://studentgamedev.blogspot.se/2013/08/unity-voxel-tutorial-part-1-generating.html (but I left off in part 2 when he started with custom meshcolliders. That was after I found out that Unity has a 2d Edge Collider…. NICE!

For some docs on Unitys mesh: http://docs.unity3d.com/ScriptReference/Mesh.html

And a simple demo (arrow keys to scroll)

Sep 28 2014

2D Sprite Animations Part 3 (Completed)

I’m done witht the Tutorial now that I’ve spent the last week working on. << Click to play >> (req. Unity Web Player)

It was a very good tutorial, and I think it was good to make a complete project from start to end, including different screens, win/lose-conditions, sounds and publish settings. Highly recommend that tutorial for anyone who’s new to Unity!

I also found a cheat sheet to the keyboard shortcuts in Unity. Good one to note is Ctrl + P to test the current scene. http://blogs.unity3d.com/2011/08/24/unity-hotkeys-keyboard-shortcuts-in-unity/

Sep 25 2014

2D Sprite Animations Part 2

Tired tonight. Only got one new part of the tutorial done, but it’s one long part left. Will have to be tomorrow: http://www.raywenderlich.com/71029/unity-4-3-2d-tutorial-scrolling-scenes-and-sounds

The tutorial so far is actually really good! It goes a bit out of line in name of teaching, but I guess that’s ok. There is no way I’ll be able to enter in that miniLD, but I guess that’s ok too. Better to go through a few of these tutorials instead and get to know all the quirks of Unity instead of trying to learn by bashing my head against it. As soon as the tutorial is complete I’ll post a link to the final game.

Oh, and note to self: I really need to get more familiar with MonoDevelop. It works when I copy-paste code from a website, but some methods just seems like they won’t autocomplete at all, like the

void OnBecameInvisible() {}
void OnBecameInvisible() {}

I also need to figure out the keyboard shortcuts for starting the game instead of having to click on that tiny button. Peferablydirectly from MonoDevelop.

But this is a common frustration when starting with a new editor =)