Implementing the Clamp and UI in Unity

In my previous post, I implemented the 3D model and control logic for a telescopic rotating arm with Lerp() to animate the rods and visualize the behavior.  In the code update, I changed Lerp() to RotateTowards() and MoveTowards() in a Coroutine to make the movement seem more mechanical versus the spring effect of simple Lerp() and introduced on-screen buttons to supplement keyboard input.

I modified the model to have a clamp, using simple boolean difference to cut through the original cylinder and then separated the halves.

Clamp2-1-Section

The key step is to move the pivot to the end connected to the arm to rotate as a clamp.

Clamp2-2-Pivot

Updated the original model to have the Left and Right Clamp objects and renamed the Rods (Arms) to count from 0 (zero) –to be code consistent. I created a new script to handle Clamp behaviors instead of adding the functionality on the Telescopic script since I will have other Clamps connected to other devices.

Clamp2-2-UnitySetup

The script commands are exposed as public methods that can be invoked from a master control script (I wanted to name it program as in MCP but it’s called a script in this world)

Clamp2-3-UnityInput

Added buttons to simplify controls and they can invoke the public script methods.

Clamp2-4-UnityButtons

The sample WebGL app is posted at:

http://orbitalfoundry.com/WebGL/Factory1B/index.html

Clamp2-5-AppSample

For questions, comments or contact – follow/message me on Twitter @rlozada