From colliders to maths


I had a couple of long write-ups about the details of how I ended up implementing this, but I think it's too much to post here.

In summary: I switched the system from just using colliders to see if two cogs' teeth were in contact, to calculating the angle.

I hit a lot of problems on the way, each time causing me to question whether this approach was even viable. I got stumped by inaccurate Unity documentation, the unexpectedness of clockwise rotations requiring a negative value(?!!) and many things breaking on the way.

I got it all working only to find that the accuracy was still a problem, because a partial cog would overshoot it's rotation in the last frame in which it was in contact with the driving cog. In the end, I had to add an adjustment in that frame which snaps a cog to the nearest 1/8th of a rotation. As with everything so far in this prototype, it proved to be very fiddly, because any adjustment to one cog's speed or rotation has to then be passed down the chain to all the other cogs. I also had problems with cogs getting jammed - e.g. in the gif below, if the two half cogs are detected as both colliding with the big blue cog at the same time, the system would jam.

I don't know if I've solved all these problems.

Trying to create this system has felt like a game of whack-a-mole, and I think one of my biggest mistakes was not having a scene with all these sample cog systems in place for testing. Every time I run the scene, I drag and drop cogs around to see if it's working, but given the intricacy of the system this is definitely not enough. I would often find I had fixed one thing, and later stumble into a problem with partial cogs, or compound cogs, or cogs of a different size, etc.

My next step if I continue trying to work on the code behind the system would be to create such a scene for regression testing.

Leave a comment

Log in with itch.io to leave a comment.