Just so you know, this is not a tutorial series! I am writing this series mainly to give you a behind the scenes look at the process of making a game in Unity, and to document the development of this project.
I made a lot of progress since the last update in this series, mainly to do with ship mechanics. I got the ship’s colliders all set up, sorted out steering, wrote a few shaders, and fixed player movement. Unfortunately I severely overcomplicated stuff (more than once), which cost me some time, but it was still a productive two weeks.
This afternoon I finished off the ship model’s steering wheel and added some railings.
Today I polished up a few parts of the ship and imported the model into Unity. After ensuring that all the face normals were pointing the right way, I proceeded to add some materials.
I then adjusted the flotation values to work with the actual size of the ship. Next, I made some modifications to the flotation mechanics to make them a little more realistic looking. Finally, I played around with the ocean shader some more and made that look a lot nicer.
Obviously, the model isn’t 100% complete. It’s still missing cannons, a ladder to the crow’s nest, and various other bits and pieces. However, this is where I’ll be leaving it for now, since it gives me plenty to work with for the next few weeks.
Today I wrote a little script to export a model’s vertices into a file. This will allow me to feed the vertices to the server’s physics engine and create more complex colliders (such as the ship’s hull).
At the moment this method is working, however the scaling and rotation are off. This is due to the mesh having been rotated and scaled within Blender, without the physics engine knowing about it. Another problem is that the exported file contains about four times as many vertices as the model in blender. I’m fairly certain this is caused by the fact that my model is flat-shaded (low poly) which requires splitting vertices and normals, thereby increasing the amount of each.
Today I fixed up the model. All the model’s objects now have a scale of one and are rotated properly. I also changed the ship’s render mode to smooth, so now the exported vertex count is accurate. The model itself now looks quite strange, but thanks to my low poly shader I was able to retain the faceted look in-game.
Additionally, I wrote a shader for the skybox to give it the low poly look as well. I also gave player’s the ability to jump, but unfortunately completely broke player movement in the process.
Despite today being another busy Friday, I managed to fix ship flotation. While it works again, something about it looks different, so I’ll be making some more modifications to that soon.
I also got player movement working again, but it’s not the way I want it to be yet so I’ll have to look into that some more tomorrow.
Today I sorted out player movement—once and for all this time. It turns out that the BEPUphysics library actually includes built in character controller movement, which means I did a lot of unnecessary vector math. It’s now working beautifully, and the code is much more readable and compact.
This afternoon I wrote a blog post about getting started in game development with Unity and C#, which left me with little time to work on the project.
Today I started by organizing the Blender model of the ship. Everything was in the root of the hierarchy, making it an absolute mess to look at. Now everything is properly nice and tidy.
I then proceeded to add colliders to most of the ship (crow’s nest and a few other parts are still without). In singleplayer games this is a quick and straightforward process, but since my collision system runs server-side, it’s more involved. I started by adding colliders within Unity and positioning them appropriately. Next, I wrote a script which takes the colliders’ scale, position, and rotation, and formats it into lines of code within a text file. This allows me to simply copy and paste this code into my server and it sets up my colliders for me.
This morning I added a spawnpoint on board the ship and made players spawn there when they join the game. Then I made it possible to return to the ship by pressing ‘G’, but that’s mainly for testing purposes.
Later in the evening, I gave players the ability to interact with the steering wheel by pressing ‘F’, and to turn it using ‘A’ and ‘D’.
Today I added a little more detail to the ship’s steering wheel by changing the colour of the handles. Then I spent several hours writing and testing various flotation algorithms, since the old one completely broke down when the ship moved horizontally. I think I’ve finally found one that will work, but it still needs quite a bit of fine-tuning.
This afternoon I spent quite a bit of time trying to convert Quaternions to Euler Angles (since BEPU doesn’t have any such functionality built in). I finally found a method that works properly, but it turns out I didn’t even need it.
I had been trying to get the ship to turn when the player turns the steering wheel, and for seem reason I came to the conclusion that I required a conversion between Quaternions and Euler Angles. Steering is now working, but it’s a little annoying that I spent so much time on something I don’t currently need. I’m really hoping that I’ll find a different use case for my Quaternion-to-Euler code.
I didn’t have too much time today, but I made a few changes to the ship model. I lowered the steering wheel, added extra stairs to make walking up and down smoother, and I corrected the rudder’s origin point so that it can turn properly.
This afternoon I cleaned up my logger class a bit and changed how it prints out each line (when a message’s length exceeds one line).
Then, after a few hours of trying out different mechanisms, I finally solved the issue of ships drifting when turning. Of course I had been overcomplicating it again, trying to get rid of the drift by applying a correctional force. Eventually I found a thread about this very problem on the BEPUphysics forums in which it was pointed out that you could simply remove the ship’s sideways velocity. I think part of the reason why I didn’t try that was because setting an object’s velocity directly feels kind of hacky—as though it could easily break something if not done properly.
Today I spent more time trying to get my flotation working so that it looks realistic. Unfortunately the ship is still being pushed up too high and then it “hovers” in mid air for a moment. I ended the day by finishing and editing this post.
Over the coming two weeks I’ll continue to work on flotation—I’d really like to get that sorted out. I also found an article about achieving the low poly look without using a geometry shader, so I’ll probably be writing some shaders. If I manage to get that all done, I will probably work on the ship some more, since it’s missing ladders, cannons, etc.