Search Unity

Games [WIP] GearBlocks - Build working physics based machines and mechanisms [DEMO]

Discussion in 'Projects In Progress' started by danger726, Mar 24, 2015.

  1. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Tutorials, and quick / auto save

    Time for a quick update on what I've been up to over the past couple of weeks.



    The first thing to mention, in case you missed "tutorial week" last week, I released a series of tutorial videos for GearBlocks beginners, so do check those out if you haven't already. Click here for the playlist.

    Help screen

    I've been working on improving the help screen in game. There's now a section that lists all of those tutorial videos, and clicking on a link will open up the Steam overlay and play the video.



    I also added a quick reference guide to the main screen UI:



    The last section has a list of controls for the tools, but I'm planning on improving this by changing it to be more of a step-by-step "how to build" guide.

    Auto save

    Currently there's no undo functionality in the game, and it'll be a while until I can get to this, so in the meantime I've implemented an auto save feature. At least this way there's less chance of people losing all their progress from an accidental deletion for example. In the gameplay options menu the time interval between saves can be configured, or auto save turned off altogether.

    Right now there's only one auto save "slot", but I'd like to add multiple save slots (e.g. two or three) that it cycles through.

    Quick save / load

    I've also implemented quick save and load. Pressing F5 saves the world (again, there's currently only one save slot). Holding F9 for half a second will load the last saved world (whether it be from an auto, quick, or regular save).

    Hopefully all of these improvements will make life easier for both new and experienced players!
     
  2. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.6.7706

    Just released a minor demo update with the help screen improvements and quick / auto save!

    Steam store page

    Release notes:-
    • Improved help UI screen, now lists links to tutorial videos, and has a quick reference guide.
    • Implemented basic quick save / load world functionality (using F5 / F9 keys respectively by default).
    • Implemented basic auto save world functionality with a configurable time interval between saves (see “gameplay” options menu).
    • Bug fixes.
     
  3. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.6.7734

    Hey all, I’ve just put out another minor demo update, just a few tweaks and bug fixes in this one.

    Steam store page

    Release notes:-
    • Added check to prevent too many parts from being spawned.
    • Increased camera far clip distance and shadow draw distance.
    • Bug fixes.
    • Upgraded to Unity 2019.4.21.
     
  4. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Hey everyone! Things have been kinda hectic lately, I'm currently in the process of finding a new place to live, which has been quite disruptive to getting work done on the game. But, I'm still slowly making progress, so time for a long overdue update I think.

    As you may know, in the past I've gone back and forth on whether to change the building system in the game to make it more user friendly. Although many people have gotten used to the current controls, I still think that quite a few (especially new players) find them a bit awkward and off-putting. I really should have dealt with this a long time ago, but I just couldn't think of a design that I was happy with, so to be honest I just kept putting it off. Anyway, lately I've been having another go at prototyping some new ideas to try and address these problems once and for all.

    I've made a dev diary video on all this, that way it's a bit easier to explain what I've been working on!

     
    Antypodish likes this.
  5. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    It's been a while, so time for a quick progress update! I've moved into a new place now and I'm back up and running, so that distraction is out of the way thankfully. I've been continuing work on trying to improve the building system. Part multi-select is now pretty much done, and I've been trying out some ideas for selection rotation, check out the latest dev diary video for more details.

    These changes are in the demo pre-release branch on Steam, so give that a try and let me know what you think!

     
    Antypodish likes this.
  6. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    The work on improving the building system continues, with new transform manipulators, and a better way to align parts together.

    The demo pre-release branch is updated now with the new manipulators and alignment system.

     
    Antypodish likes this.
  7. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Another dev diary, this time discussing improvements to the existing builder tool manipulators, and introducing a new part resizing manipulator.

    As always, I’ve updated the demo pre-release branch with these changes to the building system, so you can try them out and let me know what you think.

     
  8. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.7969

    Hi everyone, I've now updated the demo main branch with all the builder tool changes from the past several months, so I thought it would be a good idea to summarise everything here.

    Part multi-selection

    The builder tool controls for part selection and movement hadn't really changed much since early on in the project. Left clicking on a part in a construction would toggle selection on, and then the mouse (and player movement keys) would move the whole construction around. Clicking again would deselect (and unfreeze) it. Holding the right mouse button on a part would detach it from the rest of the construction.

    However, I wanted to introduce the ability to select multiple parts of a construction and manipulate them together, independently of the rest of the construction. The old selection controls didn't adapt well to this, so I re-implemented them to adopt a "drag and drop" paradigm.

    So now, left clicking on a part selects only that part (not the whole construction). To move the selection around the left mouse button has to be held down while dragging, and releasing the button will stop moving it, leaving it frozen in place. Releasing the selection while aligning it to another frozen part will attach it to that part.

    The right mouse button no longer detaches a part (it now always deletes it), because a part can be detached simply by selecting and dragging it away from the rest of construction.

    In order to select multiple parts of a construction, holding left control and left clicking on a part will add or remove it from the selection. Then, all selected parts can be moved around together, allowing for easier modification of sub-sections of a construction.

    Often it's still useful to move an entire construction around, and to do this all of its parts must be selected to avoid breaking it apart. Holding left control and pressing A while targeting a construction provides an easy way to do this.

    Finally, left clicking while not targeting anything will deselect any parts currently selected.

    I've also tweaked the part highlighter rendering to more clearly convey the distinction between unfrozen, frozen, selected, and targeted parts. Frozen parts are outlined in blue, selected parts in orange, and the targeted part in white. An example of this can be seen here:



    Move manipulator

    Building on the part selection changes, I wanted to introduce the concept of manipulators, kind of like "sub tools" within the builder tool itself. The idea being that they provide an easier and more obvious way to perform certain transformations on the selection (e.g. translation, rotation, etc.) The first of these to discuss is the move manipulator, I'll go over the others later on.

    The first step was to implement a way to author pivot points for all of the parts, and to make it possible for the player to target and select them. The selected pivot point then provides the anchor for transforming the selection with the manipulators (being the centre of rotation for example). The targeted pivot point is indicated by a small circle as can be seen in the previous image.

    Next, I factored out the code for clicking and dragging the selection from the builder tool, forming the basis of the new move manipulator. It provides drag and drop behaviour in much the same way as before, except that I also added a more obvious draggable "handle" (positioned at the selected pivot point). Pivot points can only be targeted on selected parts, but clicking and dragging on an unselected part will select it and also select the closest pivot point all in one go, as a shortcut to help speed up building.

    Once a pivot point is selected, the selection is detached from any unselected parts in the rest of the construction, and the move manipulator handle appears as a larger circle, as seen below.



    In the example shown the selection is being aligned to another frozen part, and a valid attachment is possible, so the selection is outlined in green. If the attachment was not valid (e.g. due to part interpenetration) it would be outlined in red.

    By clicking and dragging the move manipulator handle, the selection can be moved, allowing it to be repositioned, aligned for attachment, or detached altogether.

    The pivot point can be deselected by left clicking while not targeting a selected part, this will attach the selection to any other parts it's being aligned to (if a valid attachment is possible).

    I also carried over the shortcut keys for use while dragging the move manipulator handle. Holding down left shift and moving the mouse translates the pivot point (moving the selection under the crosshair). Holding down left shift and using the directional keys (e.g. WASD) will rotate the selection in 90 degree steps. Holding down left control and using the directional keys will resize the selected part (if applicable).

    These shortcuts are mostly the same as with the original building controls, even holding the right mouse button to rotate the selection with the mouse still works, for those who are used to the old way.

    Recap of the builder tool controls

    Selecting parts:-
    • LMB to select the targeted part (and deselect all others).
    • Left control + LMB to add or remove the targeted part from the selection.
    • Left control + A to select all parts of the targeted construction (and deselect all others).
    • LMB while not targeting any parts to deselect all.
    Moving the selection:-
    • LMB on a selected part (or hold LMB and drag on any part) to:-
      1. Select the targeted pivot point.
      2. Show the move manipulator.
      3. Detach the selection from any unselected parts in the rest of the construction.
    • Hold LMB and drag the move manipulator handle to move the entire selection, align it to other frozen parts, and so on.
    • LMB while not targeting a selected part to:-
      1. Attach the selection to any other parts it's being aligned to.
      2. Hide the manipulator.
      3. Deselect the pivot point.
    Shortcuts while dragging the move manipulator handle:-
    • Hold left shift and move the mouse to translate the selection under the crosshair.
    • Hold left shift and use the directional keys to rotate the selection in 90 degree steps.
    • Hold left control and use the directional keys to resize the selected part.
    • Hold RMB (or left shift + RMB) for legacy mouse rotation.
    • Mouse wheel (or hold left alt and use mouse) to "dolly" the selection.
    Other:-
    • Hold RMB to delete the targeted part.
    • Left control + D to duplicate the targeted part.
    • Left control + F to freeze / unfreeze the targeted part.
    There is a lot to remember here, but the in-game UI overlays are there to provide a reminder of the available actions and key bindings in the current context.

    Alignment targeting

    Until now, to align and attach the selection to another frozen part, the crosshair would have to be directly over the frozen part being aligned to. I don't think this is very intuitive, so I re-implemented the system to use a volume based on the selected pivot point to find the part to align to.

    Before, a Raycast would be fired forward from the player's viewpoint to find the part. Instead now, it uses a BoxCast (again directed forward from the player's viewpoint). A part's selectable pivot points are typically grouped together, and the group containing the selected pivot point determines the size of this box. For some parts (such as beams and plates) the box happens to encompass the whole part, for others (such as gears and wheels) it does not.

    The image below shows one beam being aligned to another without the frozen one needing to be directly under the crosshair.



    In some cases however, the more precise Raycast method is still preferable. For example, inserting a beam in between two other beams is hard to do with a BoxCast, because the selection will tend to align to the outside of one of the beams, as shown here.



    So the final solution I came up with was a combination of both methods. First a Raycast is tried, and then if that doesn't find a part to align to, the BoxCast is attempted as a second step. This allows for more precise targeting when needed by aiming the crosshair over the desired part. In the beam example, this makes it easier to insert the part, as shown below.



    The other manipulators

    In addition to the move manipulator, I've also implemented manipulators specifically for translating, rotating, and resizing the selection. These manipulators can be switched between using the R, T, and Y keys respectively. Pressing the key for an already selected manipulator will disable it, leaving only the move manipulator active.

    Translation manipulator

    The translation manipulator has handles that can be targeted and dragged to translate the selection along the x, y, and z axes (oriented relative to the pivot). It also has shortcut keys, holding left shift and using the directional keys will translate the selection in unit steps.



    Since the last dev diary video, I've also implemented code to align the selection while using this manipulator. To do this it uses a BoxCollider, again taking the selected pivot point group for size, and positions it relative to the pivot point. It then detects collision contacts against the collider with frozen parts, to find any directly adjacent ones to align the selection to.

    Rotation manipulator

    The rotation manipulator also has draggable handles, in this case to rotate the selection around the x, y, and z axes. Again, it has shortcut keys, left shift and the directional keys will rotate the selection in 90 degree steps. It will also now align the selection while rotating it, in the same way as the translation manipulator.



    Resize manipulator

    A long standing request from some players has been to make part resizing easier and more intuitive. The resize manipulator is now there to achieve this, it provides draggable handles to resize the selected part. Just like the other manipulators it also has shortcut keys, left shift and the directional keys will resize the part in the available resizing directions.



    This manipulator is only available for use if a single part is currently selected (and that part is resizable of course). Resizing multiple parts together is not possible, although I may revisit this in the future.

    Summing up

    OK, that's about it for this update! Sorry it was a long one, despite skimming over a lot of details.

    There's still a lot more I want to do to further improve the building controls, and extend their functionality, but I think I now have a solid basis to work from. The most important thing now is to implement some tutorials to introduce players to building in GearBlocks, so that's what I'll be working on soon.
     
    Antypodish likes this.
  9. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.7985

    OK, I’ve just released a minor update to the demo with a few small changes.

    I changed part duplication to behave more like it did before the builder tool overhaul, so that you don’t have to hunt around for the duplicated part, and thereby hopefully speeding up the building process.

    Now, holding Left Alt + LMB duplicates the targeted part. After which, releasing Left Alt (while still holding LMB) allows the duplicated part to be dragged away for repositioning.

    I also fixed a couple of bugs relating to part selection and the move manipulator.

    Steam store page
     
    Edy likes this.
  10. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.7998

    Another minor demo update is now out with tweakable wheel friction and control wheel torque, and a few other improvements and fixes!

    Steam store page

    Release notes:-
    • Added sliders to the wheel's part behaviour UI for setting its longitudinal and lateral friction coefficients.
    • Added a slider to the control wheel's part behaviour UI for adjusting its torque.
    • Reimplemented options serialization code so that saved settings will persist across future version updates.
    • Added button to the controls options screen to reset key bindings back to their defaults.
    • Added multiple player spawn zones to the "desert proving ground" map (spawn position chosen from a random zone when starting a new world).
    • A construction's position is now reset if it goes out of bounds of the world map.
    • Bug fixes.
     
  11. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,081
    Hello, did you have a chance to look to the new articulation exposed in Unity 2020? In Unity 2021 you can even use both classic joint and articulation in the same structure.
    Btw, are you still using capsule collider and configurable joint for the wheel contact managing and friction?
     
  12. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Yeah I did briefly, as I recall articulation doesn't allow rigidbodies to be jointed together in a "loop" (which can easily happen in GearBlocks). I didn't know about being able to combine both in Unity 2021 though, maybe there's a way to have the best of both worlds!

    Right now I'm trying to get the game ready for early access release, so I can't risk messing with the physics, but maybe I can look into this in the future, the possibilities are intriguing.

    Oh, and yes, I am still using a capsule collider and configurable joint for the wheel physics.
     
  13. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,081
    Can you please explain better how this setup works? Im not sure I got it..
     
  14. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
  15. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8024

    Just put out another small demo update with fixes to prevent cases where interpenetrating parts could be attached together.

    I also expanded the desert map to an 8x8km playable area (12x12km visible), and added a simple visualisation of the map boundary.



    Steam store page
     
  16. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8046

    Happy New Year everyone! I've just put out a minor demo update with a new selection menu, optimised intersection testing when aligning parts together, and several bug fixes.

    Selection menu

    This is a new menu that provides more ways to add and remove parts to / from the selection. It's accessible by holding the Right Mouse Button, deletion has now been moved to Left Shift + RMB by default. Of course the key bindings can be changed (in the controls options menu) if you prefer.



    With the selection menu you can:-
    • Toggle targeted part selected (shortcut key: Left Ctrl + LMB).
    • Select all parts in targeted construction, deselecting anything previously selected (shortcut key: Left Ctrl + A).
    • Add targeted construction to the selection, without deselecting anything.
    • Grow the selection, adds parts neighbouring those already selected (shortcut key: Left Ctrl + Up Arrow).
    • Shrink the selection, removes parts with unselected neighbours (shortcut key: Left Ctrl + Down Arrow).
    • Invert the selection, selects parts in targeted construction other than those already selected (shortcut key: Left Ctrl + I).
    • Deselect all parts (same as left clicking while not targeting anything).
    • An option to enable selecting both highlighted parts when targeting an attachment.
    • Destroy all selected parts.
    I hope to expand this menu eventually to include things like: the ability to hide selected parts, save & recall selections, and filter selection by part type, material, paint colour etc.

    Steam store page
     
    Edy likes this.
  17. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Building a new map

    Hi everyone, it's been a while, so time for a dev update I think.

    Over the past couple of months I've been working on making a new map for the full game. Currently in the demo there's a procedurally generated "desert" map that's a bit boring as it doesn't have much variation. So I decided to hand craft another map that would be more fun for testing wheeled vehicles, with various road and race track layouts.

    At some point I'd like to have other maps tailored towards different kinds of creations, but those will have to wait until some time in the future.

    The race track layout

    The map sizes in the game are 12x12km, with an 8x8km playable area, which is a huge area to create a map for, especially by hand. So for now I've been focusing on one 2x2km region to try and get that up to a decent quality level.

    The first step was to design a race track layout, which I did by piecing together corners inspired by some of my favourite real world tracks. I wanted to have a good mix of corner types, elevation change, and a nice flow. The track also has multiple routes, for more variety.

    The next stage was to build the race track in Unity, for this I used EasyRoads3D (http://www.easyroads3d.com/). This is a node based tool for creating road layouts that generates the road meshes, matches the terrain height to the road, and can generate other associated objects such as tunnels, bridges, kerbs, and walls. This tool isn't without its problems, it has quite a few bugs that I struggled with initially, especially when using the flex connectors to create road intersections. However once I got used to working around these issues, I found this tool to be quite powerful and flexible, and it can produce some great results.

    Here's the initial race track layout, you can see where I've used intersections to create alternate routes and a pit lane, and where the flat terrain has been automatically raised up to match the elevation changes in the track:-





    Following on from this I sculpted the terrain around the track to match it, and added a tunnel for the bit where it crosses over:-





    Terrain texturing

    Before painting textures onto the race track terrain, I first wanted to make some improvements over the terrain texturing that has been in the game so far. The textures themselves didn't really fit the visual style of the game, they weren't varied enough, and I'm not a huge fan of "cross fade" blending between the textures either.

    So I created a set of new terrain textures with a more stylised look (a mix of adapting some pre-made textures and making my own).

    I implemented height-based blending into my terrain shaders (also with gloss, occlusion, and metallic maps), this was based on the mask map support in Unity's URP (I'm using the built-in RP). I'll skip the details here for brevity, but here's a comparison between conventional and height-based blending:-





    And now here's the terrain with the textures painted onto it (and also with some tweaks to the pit lane):-





    Terrain details and trees

    The next job was to add some terrain details (grass & rocks) and trees. I implemented custom shaders for all these, in order to have deferred lighting support, and translucency on the tree leaves. I created tree models using Unity's old tree editor, which is somewhat flawed (I think it might be abandoned nowadays?), but it did the job, and besides I couldn't justify spending money on a third party tree creator tool!

    I implemented a simple tool in Unity to procedurally place the grass and rocks based on the underlying terrain textures (e.g. so I could quickly place the grass details on top of wherever the grass terrain texture is painted). The trees I just placed by hand.

    Here are some images of the final result:-











    Desert map

    I also worked on the old desert map to bring it in line with the new one, by switching over to the new stylised textures, adding grass & rock details, and adding trees. The desert map was created procedurally using TerrainComposer (http://www.terraincomposer.com/terraincomposer-2-2/), so it was fairly simple to set up and automatically place the details and trees. They definitely add a bit more life to the old map:-







    Next steps

    Overall I'm reasonably happy with how the race track map turned out so far, the track itself is a lot of fun to drive on, although visually I feel the map is still lacking something in some places. I'd like to tweak the terrain and tree textures some more, improve the pit / paddock area, and maybe place more objects (such as large rocks) around the map. Hopefully that'll help.

    More importantly, I need to finish laying out the rest of the map, by adding an oval track (I've made a start on this already), a go kart track, and an off-road track. Beyond that, I'll probably fill out the remaining outer regions of the map with more generic elements (hills, mountains, etc.) which should be less time consuming to make.
     
    newlife likes this.
  18. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8145

    Hi all, another minor demo update is out now with some small usability improvements and visual changes to the in-game maps.

    Steam store page



    Release notes:-
    • Minor usability improvements:-
      • Builder tool actions (unfreeze, duplicate part, and delete part) now work even when targeting a manipulator handle.
      • Unfrozen (individual) parts can now be directly deleted, without having to freeze them first.
      • Move manipulator part resizing now works even when "transform" and "resize" actions are bound to the same keys.
      • When no tool is active, the targeted part is only highlighted if it has an activatable or tweakable behaviour.
    • Improvements to the "desert proving ground" map:-
      • Implemented height based texture blending in the terrain shaders.
      • Replaced terrain textures.
      • Added grass and trees.
      • Implemented a rudimentary "weather" system that adjusts the sky between clear and cloudy.
      • Improved atmospheric scattering to better visually blend between the terrain, distant terrain, and sky.
    • Improvements to the "flat plane" map:-
      • Expanded its size to 8x8km.
      • Replaced floor texture.
      • Replaced sky with an environment cube map.
    • Raised boundary height to 2 km in all maps.
    • Bug fixes.
    • Upgraded to Unity 2019.4.38.
     
  19. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Scenario mode and Lua scripting

    Hey everyone, over the past month I've been back to working on the scenario mode. One of the last things I want to get done before the initial early access release is to add some in-game tutorials, and I think it makes most sense to do this using the scenario system.

    I figured the best way for the scenario mode to be flexible enough to support tutorials, as well as other kinds of challenges, would be to do it via dynamic scripting. So for each scenario there'd be a script that gets loaded at run-time, hooks into the game, and implements the tutorial / challenge logic. This would allow for user created challenges and mini-games that players can share on the workshop.

    Choosing a scripting language

    The first step was to choose what scripting language to use. This had me thinking about modding more broadly, it made sense to keep this in mind when deciding on a scripting approach.

    A lot of Unity games with scripting support for mods do it by loading assemblies at run-time, which works because the Mono back-end uses JIT compilation. This is quite an open ended option for modders, they can write scripts in C# and use whatever assemblies are available from the game.

    However, I'm using the IL2CPP back-end to eke out as much performance as possible, which by its nature is an AOT compiler and cannot load arbitrary assemblies at run-time. So, I needed to use some kind of run-time interpreter.

    I narrowed it down to two options and spent some time with both to evaluate them in the game:-

    C# using Roslyn C#
    • This is a Unity asset that provides run-time compilation of C# scripts.
    • It doesn't work with IL2CPP directly (the JIT vs AOT thing again), but there's the dotnow CIL interpreter which integrates with it and executes CIL on IL2CPP platforms.
    • However, dotnow is in early development, and has some inherent limitations.
    • I came up against some problems with dotnow, nothing that couldn't be worked around, but it's definitely a more involved process.
    • The C# language is overkill really for creating scenarios, but might make sense for modding the game more generally.
    Lua using the MoonSharp interpreter
    • This is an interpreter written in C#, no JIT, so it works with IL2CPP.
    • It's been around for a while, development doesn't seem that active, but I think it's pretty stable at this point.
    • I found hooking up Lua scripts into the game with MoonSharp to be quick and easy.
    • Lua is more than sufficient for making scenarios, and I think would be simpler to learn for players wanting to create their own.
    After this investigation and considering the points mentioned above, I decided to go with the Lua option, at least for the scenario mode and other basic mods. If I ever decide to support more complex modding (e.g. adding new part behaviours or other direct interactions with the physics engine), then C# would probably make more sense, but this will be something to revisit in the future.

    Loading and running Lua scripts

    I implemented a Lua script "manager" to handle loading Lua script files from any specified path, unloading of scripts, and to keep track of the lifetime of active scripts. It's the only code in the game that directly references the MoonSharp interpreter, which it uses to configure and execute the scripts.

    The manager also calls two specific global functions in each active Lua script if they are defined, "Update" and "Cleanup". The former is called every game update, and the latter is called on a script just before it is unloaded.

    Lastly, the manager provides functions for other game code to register types and object instances with MoonSharp. This is what enables Lua scripts to interface with game code and do useful things.

    Events and variables

    The GearBlocks code architecture is built extensively around ScriptableObjects, particularly for events and global variables which are used to communicate between separate subsystems. I covered this in some detail here if you're interested: ScriptableObjects For Fun and Profit.

    Not only was this approach useful for decoupling game code, but it also made it easy to add a debug console that allows for tweaking variables and raising events from within the game for testing and experimentation purposes. There's more info on this here: Debug console.

    It was similarly easy to expose these same events and variables to Lua scripts. Each event and variable ScriptableObject asset now registers its type and instance with the Lua script manager. This lets Lua scripts read / write variables, and raise / handle events. It means a Lua script can configure the game for a particular scenario, for example a tutorial could disable certain game features, and then unlock them as the player progresses through the tutorial.

    Here's a basic Lua script registering an event handler and modifying a game variable, note the use of the Cleanup function to remove the event handler:
    Code (Lua):
    1. local function onGameReady()
    2.     -- The game is ready, so initialise stuff here.
    3.     ShowFPS.value = true -- Turn on the FPS display.
    4. end
    5.  
    6. -- Add a handler to the GameReady event.
    7. GameReady.handler.add( onGameReady )
    8.  
    9. function Cleanup()
    10.     -- Script is about to be unloaded, so cleanup here.
    11.     ShowFPS.value = false -- Turn off the FPS display.
    12.     GameReady.handler.remove( onGameReady ) -- Remove the event handler.
    13. end
    I added two new events (handled by the Lua script manager) for loading and unloading Lua scripts. These events are called by the game's UI code when starting a new scenario mode game to load the Lua script for that scenario, and to unload it when finished. Because these events are available in the debug console, it's easy to load and unload Lua scripts while the game is running, and it also allows players to run their own custom scripts to mod the game!

    Proxies

    Some of the events and variables now available to Lua scripts depend on Unity types: Vector3 and Color32. Rather than expose these directly to Lua, I created proxies for them - wrappers that contain an instance of the relevant type, and expose a subset of their properties and methods. These proxy types are registered with the script manager to be made available in Lua scripts, both for using with the associated events and variables, and also for using the types directly (e.g. for doing vector math operations).

    Input

    In order for Lua scripts to access player input, the relevant game interfaces and the input system are now registered with the Lua script manager. This exposes the enums for input action IDs, and functions for finding if the key bound to an action is triggered or held.

    Here's an example Lua script that checks if a particular input action is triggered, note the use of the Update function to poll the input:
    Code (Lua):
    1. local function onGameReady()
    2.     -- The game is ready, so initialise stuff here.
    3.     ShowFPS.value = true -- Turn on the FPS display.
    4. end
    5.  
    6. -- Add a handler to the GameReady event.
    7. GameReady.handler.add( onGameReady )
    8.  
    9. function Update()
    10.     -- For no good reason lets toggle the FPS display whenever the jump key is pressed!
    11.     if InputActions.isTriggered( actionID_Jump ) then
    12.         ShowFPS.value = not ShowFPS.value
    13.     end
    14. end
    15.  
    16. function Cleanup()
    17.     -- Script is about to be unloaded, so cleanup here.
    18.     ShowFPS.value = false -- Turn off the FPS display.
    19.     GameReady.handler.remove( onGameReady ) -- Remove the event handler.
    20. end
    Custom user interfaces

    Finally, I've implemented a basic UI system that registers itself with the Lua script manager, and allows Lua scripts to create their own custom user interfaces. This is required for tutorials to relay instructions to the player and so on, but it'll also be useful for creating custom tools and mods in the game.

    A script can create a UI window (or multiple windows if needed), and then add UI elements to it. So far I've implemented text label and button elements, but I'll be adding more as I go.

    Here's an example Lua script that creates a window and adds a text label and a button to it, note the alignment options I've exposed to Lua scripting for positioning and sizing the window and the elements within it:
    Code (Lua):
    1. local function onTextButtonClick()
    2.     print( 'Text button was clicked' )
    3. end
    4.  
    5. local function onGameReady()
    6.     -- The game is ready, so initialise stuff here.
    7.  
    8.     -- Create a UI window.
    9.     Win = Windows.createWindow()
    10.     Win.setAlignment( align_RightEdge, 20, 200 ) -- Width 200, offset 20 from right edge of screen.
    11.     Win.setAlignment( align_TopEdge, 80, 250 ) -- Height 250, offset 80 from top edge of screen.
    12.     Win.title = 'Test window'
    13.     Win.isDraggable = true
    14.     Win.show( true )
    15.  
    16.     -- Add a text label.
    17.     Label = Win.createLabel()
    18.     Label.setAlignment( align_HorizEdges, 10, 10 ) -- Offset 10 from left and right edges of window.
    19.     Label.setAlignment( align_VertEdges, 50, 10 ) -- Offset 50 from bottom edge and 10 from top edge of window.
    20.     Label.alignment = textAnc_MiddleCenter
    21.     Label.fontSize = 18
    22.     Label.text = 'Hello world'
    23.  
    24.     -- Add a text button.
    25.     TextButton = Win.createTextButton()
    26.     TextButton.setAlignment( align_HorizCentre, 0, 100 ) -- Width 100, centered horizontally in window.
    27.     TextButton.setAlignment( align_BottomEdge, 10, 30 ) -- Height 30, offset 10 from bottom edge of window.
    28.     TextButton.onClick.add( onTextButtonClick )
    29.     TextButton.text = 'Click me'
    30. end
    31.  
    32. -- Add a handler to the GameReady event.
    33. GameReady.handler.add( onGameReady )
    34.  
    35. function Cleanup()
    36.     -- Script is about to be unloaded, so cleanup here.
    37.     Windows.destroyWindow( Win ) -- Destroy the UI window.
    38.     GameReady.handler.remove( onGameReady ) -- Remove the event handler.
    39. end
    And here's the result when you run the script in game:



    OK that's it, thanks for reading if you made it this far! Right now I'm starting to rough out some tutorial scenarios, and I'll continue to extend the Lua scripting functionality as required for this, hopefully I'll have another progress update on this soon.
     
    Last edited: May 27, 2022
  20. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Scenario mode and Lua scripting continued

    Hi all, time for a long overdue progress update on the scenario mode, Lua scripting, and tutorials. This will continue on from the last blog post so check that out if you haven't already. Okay, let's get stuck in!

    Code interfaces

    Exposing the game's events and global variables to Lua scripting was a good start, but only allows the scripts to do pretty basic stuff. To properly open things up, scripts need access to entities in the game (such as players, tools, constructions, parts, and so on), so I've added interfaces for a whole bunch of classes in the game code and registered them to be accessible from Lua scripts.

    I won't go through everything in detail here, but here's a brief overview of some of these interfaces:

    IConstruction
    • State properties (is frozen, total mass, velocity, etc.)
    • List of parts making up the construction.
    • Methods to get a member part from an index, for moving the construction, and so on.
    IPart
    • Part's attachments (allowing access to each attachment's position, connected part, etc.)
    • Material properties (mass, strength, is paintable, etc.)
    • List of part behaviours.
    IPlayer
    • State properties (camera mode, is in free flight, velocity, etc.)
    • Targeter (to get currently targeted part).
    • Part inventory (mode, available part catalogue, etc.)
    • Toolbox (to get the active tool and the part selection).
    IPartSelection
    • State properties (pivot part, is currently aligning, etc.)
    • Currently selected parts.
    • Methods to modify the part selection.
    This is by no means a comprehensive list, but hopefully gives a flavour of what's available. I've made functions accessible from Lua scripts that can get hold of the game's construction and player instances, and then interrogate / manipulate them via these interfaces.

    More UI features and proxies

    Following on from the UI windowing system I covered in the previous blog post, I've made more UI elements available that can be added to a window from Lua scripting: toggle, slider, drop-down menu, input field, and picture (displays an image texture).



    To support the interfaces, UI features, and Lua scripting in general, I had to add some more proxies for Unity types and static methods. These are: Quaternion, Time, Input (for raw input as opposed to key bound input actions), Texture (includes a function to load textures from file), and Rect.

    Script mods

    A Lua script can serve many purposes, but I think they essentially fall into two main use cases, a scenario script or a "script mod". A scenario script is loaded and run automatically when the player starts playing a scenario and is there to configure the game for that particular scenario. Whereas a script mod can be loaded at any point and can implement a tool, a custom UI, and so on.

    Lua scripts can be loaded from any path location using the debug console, but I've added a UI screen for an easier way to load script mods from a "standard" location (this being a ScriptMods folder alongside the SavedConstructions and SavedGames folders). This UI screen also allows for publishing script mods to the workshop and loading those downloaded from the workshop.



    I've written some simple tools as script mods that make use of some of the interfaces mentioned earlier.
    • Player tool: displays player's ID and current state (position, velocity, etc.)
    • Construction tool: displays current number of constructions, allows debug functionality to be enabled (e.g. "show part bounds"), and for a construction to be made non-targetable or even invisible.
    • Part inspector: shows targeted part's ID and current state (position, rotation, etc.)
    • Attachment inspector: shows targeted attachment's position, connected part, etc.
    Here's an image showing all of these tool scripts running at once:



    Some of these tools are useful for making scenarios, and they also serve as examples of how to write script mods, so I'll include them with the game.

    For example, the part inspector can be used to find out the IDs of parts and constructions in a scene, and then those IDs can be used in a scenario script to reference those particular part or construction instances. Another example use would be preventing certain parts from being detachable or constructions from being targeted.

    Checkpoints

    For the tutorials and other scenarios I wanted to have "checkpoints", i.e. a way for a Lua script to detect when a player or construction enters a particular area in the scene. So I've added a new checkpoint part that can be placed in the scene and defines a trigger volume (actually a couple of variations, a box or cylinder). These parts don't do much on their own but they provide enter / exit events for Lua scripts to handle and implement useful behaviour.

    The checkpoint parts need to be static (i.e. non movable under physics), so I had to implement a way to make a part be "pinned" (i.e. its parent rigidbody remains kinematic, even when the construction is unfrozen). This will also be needed for making a building foundation part which I want to add in the future to allow for buildings and other static constructions.

    Here's what the checkpoints look like, note they also have a customisable text label:



    I'm excited about what's now possible using checkpoints and scenario scripts, for example: timed laps with split times, obstacle courses, mini-games (e.g. vehicle based soccer, robot golf), you name it!

    Tutorials

    One of the main motivations behind scenario mode and Lua scripting are the in-game tutorials, and I'm making decent progress with these although it is slow going. It's quite tough trying to break down the game's complexities into simple incremental steps that gradually build upon the player's knowledge.

    Here's what I have made so far:

    Tutorial 1
    1. Briefly covers player movement (should be pretty familiar to anyone not living under a rock! :))
    2. Spawns a go-kart in front of the player.
    3. Introduces the construction menu and has the player use it to unfreeze the go-kart and turn it on.
    4. Gets the player used to controlling a construction by driving the go-kart, ending the tutorial once they reach a target speed.
    Tutorial 2
    1. Starts with an upside down go-kart.
    2. Introduces the builder tool and has the player use it to freeze the go-kart and select a pivot point.
    3. Introduces the translation and rotation manipulators and gets the player to use them to pick up and rotate the go-kart to be right side up.
    4. Once the player unfreezes the go-kart, has them drive it over to a checkpoint.
    Tutorial 3
    1. Starts with a go-kart with no wheels, and some loose wheels next to it.
    2. Has the player use the builder tool to position and freeze the go-kart, ready for building.
    3. Gets the player to pick up a wheel, use the rotation manipulator to rotate it, and align it to one of the go-kart's axles.
    4. Once they attach the first wheel, has the player attach the rest.
    5. Introduces the concept of attachments, and has the player target the wheel attachments and cycle them to rotary bearings.
    6. Once the player unfreezes the go-kart, has them drive it through a sequence of checkpoints.



    Tutorial 4 is still in progress but will likely introduce the idea of detaching and moving parts, and the builder tool UI for spawning new parts.

    I'm trying to make each tutorial build upon the previous one, and be a little more challenging for the player each time. As you can see I still have a way to go with this, I'm hoping things will go a bit faster now that I've implemented most of the game code support.

    I reckon I'll probably end up with around ten basic tutorials, and that's just covering the essentials of building. I might make a second more advanced series of tutorials to cover mechanical concepts, but we'll see how things go.

    Summing up

    Recently I've also done a major Unity upgrade to 2020 (I tried 2021 but it broke some UI stuff), and plowed through a whole load of bug fixes.

    Next up will be to continue working on the tutorial scenarios, and try to get those done as soon as possible. I'll also try adding some other simple scenarios, and I'm sure there'll be one or two other supporting features I'll need to implement in the game itself. That's it for this update, thanks for reading!
     
  21. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Supporting features for tutorials

    Hey everyone, here's a quick update on progress over the past month. I spent most of my time working on the tutorial scenarios, but also implementing some features that support the scenarios while also being beneficial to the game more broadly.

    Attachment locking

    For the tutorials, I wanted to be able to prevent the player from detaching certain parts from constructions in those scenarios.

    So, I implemented an "attachment locking" feature, which allows attachments to be set as locked, preventing them from being modified or deleted. Parts that are connected with locked attachments are selected together.

    To toggle an attachment locked / unlocked, you just target it and press Left Shift + E. The attachment's UI indicator shows when it is locked.



    Also, there are now options in the selection menu for locking / unlocking attachments of all selected parts.



    Now, when setting up the tutorial scenarios, it's easy to specify which parts should be non-detachable.

    Besides, this feature is just generally useful while building I think. It allows for creating "sub-constructions" that can't be accidentally broken apart, but can still be detached from the rest of the construction as a single entity.

    Compass HUD

    For scenarios that use checkpoints, I thought it would be good to try and direct the player towards those checkpoints. I figured the same solution could also be used to help the player find "lost" constructions.

    So, I decided to add a compass HUD to the top of the screen. It shows cardinal directions based on the player's facing direction, as well as the direction to any constructions in the scene.

    Parts can optionally override the default icon shown, this allows checkpoints to have their own icon to be more easily identifiable.



    Scenarios

    As I mentioned, the bulk of my time was spent working on the tutorial scenarios. This is proving a lot more time consuming than I'd hoped, but I am making progress. I have the first five tutorials mostly done now, and I'm working on the sixth one, which should hopefully cover most of the remaining basic building concepts.

    I've also started thinking about more open ended scenarios. As a test I made a "timed lap" scenario around one of the race track routes. This worked out pretty well, so I'm going to make a few more of these to include with the game.



    Help screen

    As a supplement to the tutorial scenarios, I've also overhauled the help UI screen to be a better user guide and reference. I added sections on various topics such as spawning a construction, spawning and attaching parts, changing attachment types, and so on.







    I removed the page linking to the old tutorial videos, as some of them are out of date since the builder tool changes a while back.

    Localisation

    Lastly, I've started looking into adding localisation (for translating in-game text for different languages).

    I decided to go with Unity's own localisation package, it seems to do everything required and I didn't see any need to go with a third party solution.

    Integrating this package and setting up the locales (i.e. languages) was nice and easy. Right now I have English, French, Italian, German, Spanish, and Russian locales, I can add more later as needed.

    As a test, I set up localisation just for the UI menu and screen heading text. I used Google sheets to make a text translation table (just using Google translate for now), and imported that into the game.

    This process worked pretty well, but the prospect of localising all the other in-game text is a bit daunting, I suspect the translation table will end up being pretty large. I'll have to prioritise the most important stuff and do it in stages. Hopefully I can find some volunteers to help with the translations!
     
    Antypodish likes this.
  22. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8292

    Hey all, I decided to put out another demo update, as I’ve fixed quite a few bugs since the last one, it also has some of the new features I mentioned in the most recent dev blog post.

    Steam store page

    Release notes:-
    • Implemented “attachment locking”, a way to prevent attachments from being modified or deleted.
    • Added a compass UI overlay.
    • Added “how to” pages to the help UI screen.
    • Various other UI tweaks and improvements.
    • First pass of localisation support.
    • Bug fixes.
    • Upgraded to Unity 2020.3.38.
     
  23. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Tutorials, new features and parts

    Hey all, here's an update on what I've been working on for the past couple of months.

    Tutorial scenarios

    The main challenge I've had lately is with the design of the tutorial scenarios, my original idea for these didn't work out to my liking. They ended up being rather boring and didn't give a very good first impression of the game. So I decided to try a new direction to create a more entertaining experience for first time players while introducing some basic concepts.

    Unfortunately this will likely mean scrapping some of the work I've already done, but hopefully I can reuse some of it at least. For now I'll say no more about the new tutorial scenario design, until I'm further along with it and more confident that it's going to work out.

    I found all this rather dispiriting and frustrating to be honest, so to try and keep myself motivated and move things forward, I've also been working on some other stuff!

    Building improvements

    Recently I've been playing the game a lot (to build content for the tutorial scenarios and trailer video), this has highlighted some bugs and other usability annoyances, which I've been fixing as I find them.

    For example:-
    • When detaching selected parts from other ones, the attachment types between them would be lost, and after re-attaching them you'd have to change the attachments back to the desired type. Now, the types are saved while the selection is being moved, and restored after re-attachment.
    • Part highlighting has been improved so that tools only highlight parts relevant to them (e.g. only paintable parts for painter tool).
    • Fixed several bugs (such as parts sometimes not attaching to engaged gears, random rotation after freezing a construction, part duplication issues, and so on).
    Braking

    On the subject of annoyances, I built a race car to showcase on the race track map, which was fun to drive around but really emphasised the need for proper braking.

    Electric motors provide regen braking by running them backwards, but this was hard to control. If a vehicle's wheels had insufficient grip they'd slip and the motor would spin up in reverse. So I made some changes to the motor part behaviour to address this:-
    • Above a certain speed a "braking direction" is now set, which is then used to prevent the motor from spinning in reverse after coming to a stop during braking (the braking direction is reset once directional control is released).
    • Added a separate tweakable value for braking torque.
    Electric motor regen may not provide enough braking on its own however, and so I've now implemented a new braking part behaviour for wheels (that can be activated by a bound key). This makes driving vehicles way more controllable and enjoyable.

    When braking is enabled, a brake disc is shown inside the wheel.



    I plan on adding separate brake and clutch parts in the future that will also make use of this same part behaviour implementation.

    Analog joystick control

    After spending some time driving vehicles around, I couldn't resist implementing something that would greatly improve the experience - analog control. More specifically, being able to bind a joystick axis to a controllable part behaviour (such as a motor).



    This, in combination with braking, transforms the enjoyment of driving vehicles in the game. It is optional however, and the regular bound keys are still a decent method of control.

    Chase camera

    Another thing I couldn't resist adding was a "chase" camera, which is now selectable when the player is seated. It's similar to the existing third-person camera except that side-to-side movement is smoothly locked behind the seated player, and the mouse can only move the camera up and down.

    This camera mode makes driving vehicles in a third-person view much easier, as you don't have to manually track the vehicle by moving the mouse.

    More parts and improvements

    Again, after spending time driving vehicles, I wanted to improve how leaving seats worked:-
    • Rather than having to look down at a seat to leave it, you can now simply press the "jump" action (i.e. Space by default).
    • When leaving a seat, if possible the player is now repositioned at a free position in front or to the side of the seat, rather than on top. This is more better for a vehicle with a roof for example, where before the player would just be repositioned on top of the roof.
    I also improved some other part behaviours (e.g. key bind for differential locking, tweakable light brightness) and added several more parts (e.g. seat, gear, steering wheel, connectors) to facilitate some of the example constructions I've been making.

    Grabber tool

    Finally, I decided to implement the last remaining tool in the game, the "grabber" tool. Although this wasn't a particularly high priority, it was quick to implement and I wanted to get it done so that I have the option to include it in the tutorial scenarios, without having to go back and modify them later.

    The grabber tool allows constructions to be moved around as physical objects, i.e. without freezing them first.

    It has two modes, "grab" and "shove":-
    1. Target part of a construction, then click the left mouse button and drag, to grab that part and drag the construction around by it.
    2. Target part of a construction, hold the right mouse button to charge up, then release to apply a shove force to that part of the construction.


    The grab and shove forces are configurable, as is the ability to have free or locked rotation while grabbing.

    What about the full game release?

    Before the early access release of the game, there are two main tasks left I need to get done: finish the in-game tutorials and make a trailer video.

    The tutorial scenarios have not progressed to where I would have liked by now, but I needed a break from them to clear my head, and work on something else. Anyway, now I really need to focus back on finishing the tutorial scenarios, finish building content for the trailer video, and get that captured and edited.

    I was hoping to release the game before the end of the year, but unfortunately it's now looking like the date will have to slip by a few months.

    This is really disappointing I know, but by way of compensation, I've decided to do another demo release update soon, which will include many of the improvements mentioned in this post, so keep your eye out for that!
     
    Billy4184 and Antypodish like this.
  24. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8387

    Just released a demo update with new grabber tool, brakes, joystick support, building improvements, UI tweaks, bug fixes, and more. See release notes in game for full details!

    Steam store page

    Release notes:-
    • Tools:-
      • Implemented new grabber tool, for dragging and shoving objects.
      • After detaching selected parts, attachment types are now restored if those same parts are reattached.
      • Tools now only highlight parts relevant to them.
    • Part behaviours:-
      • Electric motor modified to prevent reverse spin up after coming to a stop while braking (until control is released), also now has separately configurable braking torque.
      • Added braking to "Car Wheel" part, controllable with a bound key.
      • Differential gear's locking (i.e. slip limit) can now be turned off with a bound key.
      • Light's brightness now configurable in part behaviour settings.
      • Implemented analog joystick binding for part behaviours.
      • Activation state now serialized to saved constructions / games.
      • Added option to label a part's function in the construction controls UI overlay (see below).
    • Physics:-
      • Replaced "continuous contact detection" game option with "contact detection mode" scene setting.
      • Rotary bearings now have small angular drag (to simulate friction).
    • Player seating:-
      • Player can now leave seat with jump action (i.e. pressing Space).
      • Improved player positioning after leaving a seat.
      • Added new chase camera mode, available when player is seated.
    • UI:-
      • Added new construction controls UI overlay, shown when no tool is selected.
      • Improved and expanded help UI screen.
      • Removed player stats (speed, etc.) UI overlay, this will be replaced with a script mod in the full game.
    • Removed old "Corrugated Steel" plate part.
    • Bug fixes.
    • Upgraded to Unity 2020.3.42.
     
    Last edited: Dec 19, 2022
    Antypodish likes this.
  25. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8420



    Hi all, over the holiday period I decided to take some time out to try an experiment: attempt to add undo functionality to the game. Specifically, implement a command history, to which a command would be added for each tool action (e.g. select, move, or attach parts, apply material or paint, etc.) and then allow the player to undo or redo the commands in that history.

    The game's tools were not originally built with this in mind, but the code is reasonably well structured so I thought it might be possible. The initial prototype turned out to be promising, and showed the potential improvement to usability this would bring.

    Well, I couldn't resist seeing this through to completion, and so that's what I've been working on for the past few weeks. It required substantial refactoring of some of the tool code, and took a while, but the results are well worth it I think.

    Here it is in action, I've exposed the command history to Lua scripting, and made a script mod that shows the current list of commands:-



    Implementation details

    Rather than store an absolute snapshot every time something changes, the commands in the history store relative deltas. A command keeps a record of the change that was made by a tool action. This means implementation was kind of an "all or nothing" prospect: all tool actions must be accounted for the command history (in the right order!) for everything to work properly.

    Here are the commands I ended up with, these are added to history when...
    • Select tool: ...a tool is selected (some actions are only valid when the correct tool is active, so this must go in the history).
    • Select parts: ...any frozen parts are selected or deselected.
    • Select pivot: ...a pivot point is selected, which detaches all the selected part(s).
    • Move / resize selection: ...the selected part(s) are translated, rotated, or resized via manipulators.
    • Replace attachment: ...an attachment's type is changed.
    • Lock attachment: ...an attachment is locked or unlocked.
    • Delete attachments: ...attachments are deleted (whether directly, due to the selection being detached, or due to a part being destroyed).
    • Spawn / destroy construction: ...a part / construction is spawned or destroyed.
    • Freeze construction: ...a construction is frozen or unfrozen.
    • Swap material: ...a material is applied to a part.
    • Add / remove links: ...link(s) between link nodes are added or removed.
    • Apply paint: ...paint colour is applied to a part.
    The command history has a buffer containing references to the added commands, in the order they were added. This allows for the commands to be undone in reverse order, and redone in forward order.

    The history maintains an index of the last undone command, and if a new command is added, it will go into the buffer at this point. Any commands that came after the one most recently undone will be lost.

    The buffer is a finite size (currently 256), if a command is added to history and it's full, the oldest command is removed.

    New demo

    So, the game now has full undo / redo capability (using Ctrl + Z / Ctrl + Y). This is a feature that this genre of game really should have, and I think it was worth making the effort to get it done.

    Steam store page

    There are still a couple of issues left to deal with, but it's now in a usable state, so I've just updated the demo to include it. A lot of code had to change, hopefully I haven't introduced any glaring bugs, it seems stable so far. Give it a try and let me know how you get on with it!
     
    Antypodish likes this.
  26. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Tutorial, optimisations, and other improvements

    Hey everyone, time for another long overdue update on what I've been up to lately! I've mostly been focused back on building the in-game tutorial scenario, but I've also continued working on the game, both adding features to support scenarios, and making other general improvements.

    Performance Optimisation

    I noticed some performance issues, particularly with a large number of parts or constructions, so I decided to spend some time addressing these.

    UI optimisations:
    • UI elements now only resize themselves to content when something changes, rather than every update.
    • Improved performance of link and part intersection indicators when looping through part instances.
    • Improved the compass overlay implementation (no longer sets gameobjects active / inactive).
    • Optimised the scene tool UI's construction list update.
    Other optimisations:
    • Removed unnecessary calculations from the construction update function.
    • Eliminated the composite update function altogether.
    • Eliminated or simplified some other fixed update functions.
    These changes save over 1 ms on the main thread when there are a lot of parts / constructions in the scene (totalling a couple thousand parts or so).

    Speaking of which, I've also investigated using Unity jobs to move work off the main thread. This has the potential for some more significant performance improvements.

    Here's what I have planned:
    1. Gear and pulley wheel behaviour constraint updates - The code that figures out if a pair of gears are engaged, and the location of their engaged "teeth" (info that's then used to update the ConfigurableJoints). This could be done in parallel in jobs I think.
    2. Wheel behaviour constraint updates - Each wheel does a CapsuleCast and some other trickery to approximate a cylinder that smoothly rolls on the ground. This is a prime candidate for using the CapsulecastCommand instead.
    3. Part selection's "find valid attachments" code - Does a lot of OverlapBox calls if a large number of parts are selected, should be perfect case for replacing with the OverlapBoxCommand.
    4. Collision contact reporting (used for impact sounds etc.) - Horribly inefficient at the moment, but Unity just introduced the Physics.ContactEvent, which should be exactly what I need to improve this.
    All but the first of these tasks will require upgrading to Unity 2022.2 though, which feels a bit risky at the moment. I'm going to hold off until the LTS version comes out.

    Unity 2021 upgrade

    In the meantime however, I have upgraded to Unity 2021.3 LTS. I had tried upgrading to 2021 a while ago, but found a couple of game breaking issues. These seem to have been fixed now, and the upgrade went pretty smoothly this time.

    The only slight issue is that old saved construction preview images now won't load (compressed image size needs to be multiple of 4), but this can be resolved just by re-saving them first.

    Building improvements

    I've made various minor improvements and fixes to the building system:
    • The part selection pivot point can no longer be moved below the ground, preventing a construction from being "lost" underground.
    • Now only the move manipulator handle has "drag thresholding", the translation handles move instantly.
    • Engagement indicators are now shown for all gears in the part selection during alignment.
    • Commands are now added to the undo / redo history when links are removed while detaching parts.
    • Fixed a bug where destroying an unfrozen construction didn't add a command to the undo / redo history.
    Parts

    I've also made a few minor improvements and additions to the parts:
    • Implemented a resizable "L Plate" part, useful for connecting stuff at right angles.
    • Added checks for player distance and facing direction to the control wheel part behaviour (prevents the control wheel from being used when the player is too far away).
    • Added a light part behaviour option to disable shadow casting, useful if you want to save performance for a construction with a large number of lights.
    • Fixed a bug where spring damper / linear actuator pistons could be attached to the wrong alignment point.
    Here's what the L Plate part looks like:



    Lua scripting

    I've worked on various new features that are available for use from within Lua scripts (as scenarios or script mods), mostly to support what I need for the tutorial scenario.

    Video player

    Implemented an in-game video player, with an interface that allows video players to be created from Lua scripts. Here's a test Lua script, showing a video playing in a window:



    I'm planning on using this to show short explanatory video clips in the tutorial scenario.

    Scroll list UI element

    Implemented a scroll list UI element, can be added to a window like any other element, but then other elements can be added to it (including more scroll lists!) For example the undo / redo command history script mod can now show a larger history that can be scrolled through:



    Unlabelled UI elements

    Added unlabelled variants of the slider, input field, and dropdown UI elements for more flexibility. Shown here in this Lua UI unit test:



    Profiling metrics

    Exposed performance profiler metrics (e.g. memory, rendering etc.), so that script mods can implement custom profiler UI windows, for example:



    Tutorial scenario

    My original plan was to have multiple little tutorial scenarios, each one introducing a few new concepts at a time. As I mentioned in a previous post, this idea turned out to be a bit boring in practice, and didn't really create a good first impression for the game.

    So then I pivoted to having one large scenario with a lot of things to do in it, essentially combining the separate tutorials into one that are followed through step by step. However as I started to build this out I realised it was getting too big and complicated. Apart from anything else, performance was getting to be marginal with so much going on in the scene at once.

    So, I went back to the drawing board and reworked my design, trying to really focus on what concepts I wanted to introduce in each tutorial stage, and what concepts to reinforce from previous stages.

    The result is a bit more pared back than what I had before, but I think it should still be fun. It will still be a single scenario / scene containing multiple activities that the player goes through, but with less extraneous stuff.

    The first few activities will get the player used to activating and using part behaviours, using the construction menu, and so on.

    After which, each activity will require the player to do something (e.g. attach a control wheel, reposition a gear, link some pulleys, etc) that will allow them to open a box with a part inside. When they've completed all the activities they can collect all the parts together and build something out of it, as the final step (using everything they've learned so far).

    For example, the first of these activities is to simply use the builder tool to move a weight and place it on a platform. Things ramp up in complexity from there!



    The design is now complete, I have built all the individual constructions for the scenario, and made a good start on the Lua scripting. I'm planning on making another (small) map for the game, to be used for this tutorial (and any others to follow).

    This tutorial scenario is really there to get new players used to using the building controls, it doesn't go much beyond that. I would like to also build additional tutorial scenarios that teach advanced use of gears, mechanical principles, have more complex puzzles to solve etc. These will have to come after the early access release though.
     
    Antypodish likes this.
  27. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    This look pretty :)
    Steady but surely moving forward.
    Keep up good work.
     
    danger726 likes this.
  28. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    New map, and tutorial finished

    Hey all, I've made a fair amount of progress on the game over the past month, so let's get into what I've been up to.

    "Gary Island" map

    One conundrum I had while designing the tutorial scenario was where to locate it (i.e. which map to use and whereabouts on that map). I could have used one of the existing maps but they are all pretty large and "open plan", which made it hard to lay out the scene for the tutorial. I needed something small with clear boundaries that spatially confine the player.

    For a while I had been resistant to the idea of adding another map for the tutorial scenario, but it became apparent that this was going to be necessary, and worthwhile investing the time and effort in. So I decided to make a new map, an island surrounded by water, with a 250x250 m playable area.

    For long time followers of the game's development, I resurrected the water from those old procedural island maps! I was also reluctant to do this actually, as introducing water brings about a whole host of implications (what happens when you go in the water? buoyancy? drag? sound & particle effects? player swimming animations?) So for now the water is beyond the map boundary and is just there for visual effect.

    As usual, first I started with making the terrain height map:



    Then, painted the textures (reusing those from the other maps):



    Finally, added details (e.g. grass) and trees:



    Overall I'm quite pleased with how the map turned out. It has a central area (which I've used for the tutorial scenario), and other areas that are connected via paths for a bit of variety. I'm thinking this will be good for other scenarios, and also as a general starter map for players.

    Water reflection optimisations

    After bringing back the water, I needed to do some performance optimisations to the old reflection rendering implementation (water reflections are rendered using another camera with a view that is flipped upside relative to the main camera).

    I improved the code by eliminating some expensive per-frame calls (GameObject.Find(), GetComponent(), etc.) and getting rid of GC allocs. I also reduced the level of detail during the reflection render (by overriding the LOD bias, turning off terrain details, and reducing the tree LOD switch distance).

    Finally, I added a "video options" setting to make the water reflection rendering only include the terrain & sky, or be turned off altogether (falling back to a reflection probe).

    Tutorial scenario

    To finish the final iteration of the tutorial scenario, first I had to create a scene in the new map. I laid out all the constructions, checkpoints, and so on for each of the tutorial stages that the player completes in sequence.

    Then I worked on the scenario scripting, organising the Lua scripts by breaking them up into the tutorial stages. The scripts are responsible for tracking player progress through the tasks they have to complete for each stage, showing a UI window with instructions (text and videos), and helping the player get back on track if they make a mistake. This turned out to be a huge amount of work, but I think the results turned out really well.

    Here's a sneak peak of the start of the tutorial scenario:



    So the tutorial scenario is now (more or less) complete, which is a huge milestone, as that was the last major task before early access release. There's still a bunch of work to do, but I'm now in a position to prepare the game for release which is very exciting!

    Part resizing indicator

    I've implemented another indicator that shows unit dimension numbers near a part when resizing it with the resize manipulator.



    This makes it much easier to see the part dimensions while resizing, as it saves having to look down at the part UI overlay.

    Script mods

    The script mods included with the game have continued to develop. For example, I implemented a "builder tool extensions" script mod that provides an interface with options for precise part placement.

    I also improved and added to the various debug tools, and added a simple "hello world" example. I can't wait to see what script mods of their own players can come up with!
     
  29. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Demo 0.7.8563

    Hey everyone, quite a few fixes and improvements have accumulated since the last demo update, so I decided it was worth releasing another one.

    Steam store page

    Release notes:-
    • Many optimisations to UI, overlays, and indicators. Improves performance especially with a large number of parts / constructions.
    • Minor tweaks to builder tool:-
      • Click and drag "threshold" now only applies to move manipulator.
      • Prevented dragging the part selection's pivot point below ground.
      • Increased targeting distance.
      • Removed "Prevent Interpenetration When Attaching Parts" toggle from "advanced options" (still available in the demo by setting "PartPenetrationTestEnabled" to false in the debug console).
      • Added toggle to "advanced options" to disable the centre of mass indicator.
    • Modified control wheel part behaviour to check for player distance and facing direction.
    • Added option to light part behaviour settings for disabling shadow casting.
    • Implemented copy paste for part behaviour settings.
    • Improved part resizing indicator to show numbered unit dimensions.
    • Gear engagement indicators now shown for all gears in part selection when aligning.
    • Added settings to controls options to invert horizontal and / or vertical mouse rotation of the part selection.
    • Updated help UI screen.
    • Bug fixes.
    • Upgraded to Unity 2021.3.26.
     
    Last edited: Jun 12, 2023
  30. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks Gameplay Trailer – Coming to Steam Early Access this November!



    Wishlist and play the demo: https://store.steampowered.com/app/1305080/GearBlocks/

    There are many things still to improve, but it's been so long, I think it’s time to finally get GearBlocks into players hands! My planned Steam early access release date is November 9th. I’m also planning on entering the Steam Next Fest from October 9th to 16th, hopefully with a special tutorial demo.
     
  31. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    More tutorial and scripting improvements

    Hey everyone, it's been months since my last dev blog update! As you will hopefully have seen, I recently announced the coming release of GearBlocks into early access for November 9th.

    A lot of my time lately was spent preparing for this announcement. The trailer video was the biggest chunk of this work: planning, building content in game (including many new built-in constructions!), capturing footage, and editing it all together. I also improved the Steam store page and website with new screenshots, gifs, blurb, presskit, etc.

    Tutorial scenario

    I recently took the game to a local indie meetup, and had a few people try out the tutorial scenario. It was really useful and informative to watch people play it in person. The feedback was somewhat sobering though, some found it too complicated and struggled with information overload!

    So I made some changes to the tutorial to try and simplify the information presented to players, and added more code to handle edge cases where players were getting stuck.

    I've also set up a new build configuration for a special demo build with just the tutorial scenario in it, which I'm planning to use for the Steam Next Fest (coming on October 9th).

    Lua scripting

    I've continued to improve the Lua scripting interfaces, exposing more properties and methods for manipulating parts and constructions, adding more tool interfaces, and more vector / quaternion math stuff.

    Further improvements were made to some of the included script mods, including the builder tool extensions (now with the ability to set / snap the pivot position & orientation, change the manipulators to work in world or local space, etc.)

    Kit building

    For the trailer video I wanted to show time lapses of some constructions being built. I also want to try creating scenarios where the player follows instructions to build pre-designed blueprint constructions, a bit like building from a model kit.

    So I implemented a feature I'm calling "kit building", to cater for both of these situations. Parts can now be assigned a stage index and constructions have an active stage that can be set (where any of their parts in higher stages than the active one are hidden).

    I made a script mod tool for setting part stage indices, and previewing a construction's stages. I actually used this tool when capturing for the trailer, just manually advancing through the stages in order, revealing the parts.



    I also prototyped a kit building scenario with a simple Lua script to allow the player to advance through a blueprint construction's stages, automatically spawning the parts they need to build that stage. This idea has potential I think, but will need work to make it more user friendly.

    Minor demo update

    I decided to release another quick demo update, out now with some fixes and other small tweaks:-
    • Minor UI improvements, including a new "getting started" window that shows some helpful pointers when launching into a new game.
    • Improved attachment locking undo / redo (single command for multiple attachments).
    • Bug fixes (including fixing the differential idler gear centre-of-mass again).
     
  32. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    New tutorial demo now live for the Steam Next Fest, Oct 9th to 16th



    Hello all, GearBlocks is now participating in the Steam Next Fest, from October 9th to 16th!

    I’ve made an all new demo available just for this week, with the tutorial scenario. You can learn more about building in the game, and also try out some new parts, so be sure to check it out.

    https://store.steampowered.com/app/1305080/

    The old demo is still available in the 0.7.8657 build branch.
     
  33. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks in Early Access NOW!



    Hey everyone, GearBlocks has finally launched into Early Access on Steam!

    https://store.steampowered.com/app/1305080/

    Here's a quick preview of what players can expect if they buy the game:



    Thanks for following the development of the game over the years. I have plans for some exciting post launch updates, but as always let me know if you have suggestions!
     
    Edy and Antypodish like this.
  34. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Really cool looking presentation vid.
    Well done on constant progress.
     
    danger726 likes this.
  35. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Thank you!
     
    Antypodish likes this.
  36. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Congratulations!! And kudos on the good work, what you've achieved is awesome.

    I can see that LEGO Technic fans could also make very good use of it :D
     
    danger726 likes this.
  37. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Thanks, much appreciated!
     
  38. MicCode

    MicCode

    Joined:
    Nov 19, 2018
    Posts:
    59
    Congratulations on going early access, had been following your game and playing the demo from time to time.
    Got to say this game is really one of a kind with all the mechanical stuff. I enjoy playing similar title like stormwork. It's good to see more sandbox building game.
     
    danger726 likes this.
  39. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    Thanks!
     
  40. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks 0.7.8726

    Hey everyone, I’ve just released an update.

    New in the game - “attachment bridging”, a slightly easier way to do “node skipping”, with the added benefit that the attachment indicator now shows where the bridged attachments are:



    Release notes:-
    • Implemented “attachment bridging” feature and added option to BuilderToolExt script mod to enable it.
    • Added option to the selection GUI to disable selection of locked neighbouring parts.
    • Enabled rotary, linear, and linear rotary attachment types for pulleys.
    • Enabled rotary bearing attachments for angled connector parts.
    • Enabled rotary bearing attachment on steering arm part.
    • Added resizable “scaffold” axle part.
    • Removed TweakEnergyStore variable, tweaking of battery charge remaining now automatically prevented when energy consumption is enabled.
    • Added LimitedPartBehaviourTweaking variable, enabling it limits part behaviour tweaking to player input (e.g. key binds) only.
    • Added setting to video options that allows for the selection of exclusive or borderless full-screen, or windowed screen mode.
    • Added setting to game options to turn off “Start Here!” help message.
    • Added error message popup shown when attempting to unfreeze an intersecting construction.
    • Updating localised strings with Russian translations thanks to Ludanton!
    • Bug fixes.
     
    Edy and Antypodish like this.
  41. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks 0.7.8740

    Hey everyone, it’s time for another game update!

    Soap Box Challenge

    See how fast you can get down the hill under gravity alone, no motors allowed. This new scenario gives you an idea of the kind of “mini games” possible with Lua scripting, but it still barely scratches the surface really, hopefully we can push the boundaries of this more in the future. Anyway, check it out and let me know what you think.

    New Parts

    Continuous servo motors, more crown, rack, & worm gear sizes, more “hole & plate” connectors, and round ended beams.

    Part Behaviours

    Separate servo forward & reverse angles, flip pulley belts, link displays to multiple parts, etc.

    Here’s a quick look at some of these changes:



    Release notes:-
    • New Soap Box Challenge scenario.
    • New parts:-
      • Small and medium continuous servo motors.
      • 24T and 40T Hi & Lo crown gears.
      • x3 rack gear.
      • x1 worm gear.
      • More “1-Hole Plate” and “2-Hole Plate” resizable connectors.
      • Rounded and half rounded resizable beams.
    • Part behaviour improvements:-
      • Servo motor part behaviour now has separately tweakable forward and reverse angles.
      • Servo and stepper motor part behaviours now have an “angular speed” data channel.
      • Pulley part behaviour now has an option to flip belt routing.
      • Displays can now be linked to multiple other parts.
    • Motor, battery, and rotor parts can now attach to each other, and to other parts in a more consistent way.
    • Changed plate on “plate axle” connector part to be circular.
    • Tweaked material strength of all wheels.
    • Added buttons to UI screens to open containing folder in Windows Explorer.
    • Added player “free flight movement mode” setting to allow for moving horizontally rather than along the view direction.
    • Added settings to the controls options screen for disabling each of the manipulators.
    • Improved crosshair.
    • Added Hungarian translations to currently localised strings, thanks to BlueGoldFlag.
    • Bug fixes.
    • Upgraded to Unity 2021.3.33.
     
  42. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks 0.7.8754

    Happy Holidays everyone,

    I've just released another update, with a bunch of new parts!



    Clutches

    These attach two axles together, one with a fixed attachment, the other with a rotary bearing. The clutch can be engaged / disengaged with a key press, which will smoothly lock / unlock the rotary bearing.

    Clutch Gears

    These are a type of spur gear that attach to an axle with a rotary bearing only. Similar to regular clutches, they can be engaged / disengaged from the axle they're attached to.

    Brakes

    Wheels already have built in brakes that you can optionally enable, but these separate brake parts allow you to brake an axle without needing to use a wheel. The brakes attach to an axle with a rotary bearing, and to the part you want to brake against (e.g. a beam) with a fixed attachment.

    Angle Sensor

    You can attach an axle to this sensor, and link a display to it. It'll show the axle's current relative angle, RPM, etc.

    There are a few other tweaks and improvements too, here are the release notes:-
    • New parts:-
      • Angle sensor.
      • Clutches x3 and x4.
      • Clutch gears x1 to x3.
      • 32T and 48T Hi & Lo bevel gears.
      • Disk brakes x3 and x4.
    • Added brake calipers to wheel brakes.
    • Added setting to speed / altitude sensor to use imperial units.
    • Parts and materials are now listed in order in UI.
    • Bug fixes.
     
  43. danger726

    danger726

    Joined:
    Aug 19, 2012
    Posts:
    184
    GearBlocks 0.7.8797

    Hey everyone, time for a long overdue update!

    Combustion Engines - Not Ready Just Yet

    By this point, I was hoping to have combustion engines done. I tried a purely physics based approach, using separate cylinder, piston, con-rod, & crank rigidbodies, and applying a force to the piston based on the current angle of the crank. This worked reasonably well, but had problems with "phantom forces" whereby the engine got torque applied to it, sometimes flipping over the vehicle it's in. Also, using physics for all the parts like this has RPM limitations, and doesn't scale that well for sim performance.

    So I've decided to change tack slightly, I still want to keep the appearance of the moving parts (i.e. pistons and con-rods), but my plan is now to procedurally animate these in code. There's not really any need to use physics as these parts can't collide with anything when inside an engine. To apply torque to the crankshaft, I'm working on something similar to the electric motors, but with a different torque curve.

    Hopefully I'll be able to get this done soon, but in the meantime I thought it would be good to get a small update out. Here's what's in it...

    Parts

    There are now some slider versions of the 1-Hole and 2-Hole connectors, some new "angle axle" connectors, and a larger centrifugal clutch.

    Also, the rounded beams can now be resized one unit smaller than before.

    Part Behaviours

    I've improved how the invert option works for parts with a single key bind (e.g. brakes), adding a separate invert option for the joystick axis.

    You can now type in values for any part behaviour slider, by right clicking it. Even values beyond the normal slider range can be entered (but no guarantees the physics won't blow up with higher RPMs or torques!)

    No Collide Tool

    For those who want to bypass part collisions in their builds, I've added a new "PartCollision" script mod tool that can be used to disable part collisions. Parts with their collision disabled will still collide with the ground, but nothing else.

    Here are the full release notes:-
    • New parts:-
      • "1-Hole Slider" and "2-Hole Slider" connectors.
      • Angle axle 90, 180, 3 x 90, & 4 x 90 connectors.
      • Centrifugal clutch x3.
    • Rounded and half rounded beams can now be resized one unit shorter.
    • Added "invert axis" option to part behaviour joystick axis settings.
    • In brake, clutch, and differential part behaviours, replaced "invert direction" option with "invert control", which properly inverts their control behaviour.
    • By right clicking a slider in the part behaviour settings, it's value can now be edited by typing in a number.
    • Shortcuts (Ctrl+C and Ctrl+V) for copy and paste in part behaviour settings.
    • A construction can now be unfrozen (via the construction UI) while the player is seated in it.
    • Lowered minimum mouse sensitivity values.
    • Added methods to IConstructionOperations to set whether parts are collidable (and added IsCollidable property to IPart interface).
    • Added new PartCollision script mod.
    • Bug fixes.
    • Upgraded to Unity 2021.3.34.
     
    newlife and Antypodish like this.