I’ve not touched Unity in a long time (Unreal 4 is way better!) but here is the complete source to Valhalla Run, the gravity-manipulating 3D platformer that I used to win the SBU game programming competition. If you’re an aspiring game dev or just want to pick apart some code, this is for you.
Since terrain collision is awful, especially with custom character controllers, I made a script that automatically takes terrain data, creates a mesh, and then replaces the TerrainCollider with a MeshCollider using the generated mesh. I didn’t feel like giving up the fancy features of terrain drawing and exporting the mesh to a modeling program is too retro for me.
Since it’s run when the scene starts, it increases load times by a decent amount but shadows and baked stuff like that shouldn’t be changed. In order to compensate, I made it so a checkbox can be checked that puts the mesh in to the assets folder, which can then be attached manually in the editor. When you’re done testing your game you can export the generated meshes to actual assets to save load times.
Attach it to any terrain object and it will do its magic when the scene loads. I’m using low resolution height maps. You should be prepared to load for like 2 minutes if you’re not.
A lot of the script was taken from TerrainObjExporter. I had to do some changes in order to make the generated mesh exactly match up to the drawn terrain (flipping, reversing, rearranging indices, rotating). The source code is available here: TerrainToMeshCollider.
Player can now walk on any surface. Gravity fields still exist and override this ability.
A bit wonky right now.
No and I don’t think any would be related. I’ve coded for other engines before (mods) and I’ve been programming for a while. I watched like 3 basic tutorials to get used to the interface and how everything works.
Dashing works from off the ground + dashing screen effect.
Localized gravity fields. Now with cylinders.