S&box Gameplay & Content

Surf in Unity3d

surf_stonework4 by Mr.Cow

The reason I became interested in Unity3d, back in March of 2014, was to re-create Source Engine’s popular surf mechanic within Unity3d. Back then, I had no idea about anything related to game development, and although I had some programming experience, I was a complete beginner to C#. The first thing I did in Unity3d was put in a block to stand on, and a ramp shaped object to surf on. I was so clueless that I kinda expected surf to just work… that Unity, for some reason, had already implemented the movement and physics for me.

 

 

After testing and realizing it’s not going to work, I put my Google expertise to work in attempt to find a pre-made asset.  In modern games, surf and bhop are not very popular.  It’s not very realistic, can be difficult to accomplish, and it requires special logic that nobody is going out of their way to implement.  Needless to say, I had no luck finding any assets created specifically for implementing surf physics.  I felt a little bit defeated, and eventually gave up on the idea of surf physics.  I simply didn’t have the knowledge or experience to even begin with such a thing.

 


 

RTS Project

 

However, I did not give up on Unity3d.  Something ticked, and I wanted to create more.  Growing up, I was a huge fan of Blizzard games, and there’s never been anything quite like Warcraft III.  Warcraft III was old, rarely updated, and inspired by Warcraft III, I set about creating an RTS of my own.

 

 

I clearly had a long ways to go.  I toyed around with the Unity’s built-in pathfinding system.  I wasn’t satisfied with the way it felt, and back then Unity didn’t expose much of its pathfinding or navmesh data, so I started to research how to create my own.  For many months I dicked around with a grid-based A* solution.  Performance is a really big concern with grid-based pathfinding, and I quickly became aware of it.  My first implementations of A* were so slow, processing a path for even a single unit would cause unbearable stutters during gameplay.  It was around this time I learned about the Unity profiler, and I began picking apart my code’s execution times.  A few milliseconds here, a few dozen milliseconds there.  I spent weeks, months even, optimizing my pathfinding, until eventually realizing that the A* algorithm itself is slow.  It was at this point I began thinking outside the box – fast pathfinding requires either a low resolution graph, tricky techniques, or pruning to reduce the amount of searched nodes.  I won’t go into too much detail on this, all I can say is I spent many months trying to build the perfect grid-based pathfinding, and even today, although my pathfinding system is fine for gameplay, I remain unsatisfied.

 

 

*gasp*

After achieving a usable state with my pathfinding library, I decided that I want my game’s content to be separate from Unity3d, that way modders can use external tools or scripts to design gameplay.  Keep in mind, I was a complete beginner at this time.  My goals were hugely ambitious for how much experience I had.  I spent months learning about runtime scripting and trying to implement solutions for languages like Lua or Python.  I finally settled with Lua, because it had some popular libraries with plenty of support and documentation to learn from.

Then it was time for multiplayer.  Oh boy, did I fuck up.  I spent about 7 months writing this elaborate RTS project, but I never actually learned anything about networking or multiplayer.  Well, I began reading into networking models.  I learned all about deterministic lockstep, and the fact that it was used in Warcraft III had me sold – I wanted to be just like Warcraft.  It wasn’t long before I realized that my entire codebase would have to be rewritten, nearly from scratch, in order to implement proper networking.  Despair hit me and I said fuck it, I’m not doing it.

I gave up on my RTS dream and took a break from Unity for a few months.  I was defeated, I spent all this time trying to build something great, and a very poor foundation resulted in something unusable.  This was sometime in 2015, I believe.  I went back to work in physical labor, something that I knew was going to pay the bills.  I tend to cycle between unemployed and employed, while I’m employed I hate my life because it’s not what I want to be doing, and while I’m unemployed I hate my life because I’m not earning money doing what I want to be doing.

 


 

ARPG Project

 

I’m always drawn back to Unity – I love C# and I love creating games.  I spent some time working on a multiplayer ARPG game inspired by Diablo II, this time with a much stronger foundation and knowledge in networking.

(skip around)

 

My codebase was perhaps a little bit sloppy, but the netcode was solid.  I devised a way to run both the client and server simultaneously on one instance of Unity, which would allow me to develop very efficiently.  The client and server were completely separated from each other, and for debugging I would color code my gizmos or tag my logs to easily tell apart the client and server.  This was a fun project, and I put a lot of work into it.  Probably at least 10 months of work.  I came to conclusion that a secure multiplayer ARPG game requires a lot of time, and a lot of resources.  Resources, and time, which I do not have.  I dropped the project in favor of a single player ARPG, which is a much more reasonable goal for one single programmer.

My single player ARPG built off of ideas and solutions that I acquired from developing the multiplayer ARPG.  Eventually, I got bored.  I don’t care about single player games, I don’t even play them.  This project was destined to die off, although I did spend a good few months with it and gained some worthwhile knowledge.

 


 

Surf Project

 

This month I returned to my roots.  I remembered why I got into Unity3d in the first place, and with all of my new knowledge, I set out to re-create surf physics.  It took less than a week, and the process was quite smooth.  In the first day I was able to implement the basic mechanics, and I had surf which was functional, but still kinda shit.  After dicking around with PhysX and getting things to work properly without programming my own physics engine, I’m happy to say my surf feels very good.  I’ve gone full circle.  I’m enjoying it so much, that I want to create a full game out of it.  The game will be PvP based with dedicated servers and matchmaking.  It will play out much like Rocket League, but people flying around with guns and knives instead of hitting balls with little rocket cars.  It’s an exciting project for me, and I hope it’s something that I can stick to.  The scale of this project is not insane like my previous ones, and I believe I have the capacity to see it through.  I’m a little concerned about implementing proper FPS netcode, but I know my foundation is now solid and the process will be iterative (as always).  If something feels like shit, I’ll learn why, and I’ll come up with a solution.