Implementing tube bending for Neon Atelier



With tube bending being an core element for neon light craft, as we implemented the tube gripping mechanism, it is natural to us to also work on the tube blending along the way. Rather then wrriting a separate script, we implemented the  tube bending part by expanding the TubeGripManager from our previous blog, as the bending mechanism follows shortly after an grip step, and also reads for the same active PathContainer reference used by the TubeGripManager.

We isolate our aims for the bending motion first by setting both an start point and endpoint of the bending. Instead of moving in straight line for the bending, the motion ought to be in curve, accounting for the volume of the tube. While the bending is expected to go forwards only (the quest are not about free forming editing), we do have to account for situation where player release the grip during mid way of bending. In this case, the tube should remain partially bended, with the grip collider in appropriate position to be grabbed again.



For the actual implementation, a Bezier curve is used to define the bending motion curve which the player should follows. The Unity Splines package provides us with excellent built-in tool to implement this path, via its SplineContainer object and editor. It also provide us with utility functions that interpolates a curve and calculate distances from it. There is some caveat from the Splines package though, as its SplineContainer work a bit strangely as child to our PathContainer object, probably due to it is designed to work with static objects. Fortunate of us, the Unity's Transform has utility functions for conversion between different object spaces, and an workaround for Spline's object space is easy to work with.

With the SplineContainer ready, we can implement the bending grip control around it. We started by first detach the left grip and disable its collider from the script as the TubeGripManager is trigger into bending phrase. This prevents updating the tube transform using multi-grip when the player binds the tube. As the player move the grips in an bending motion, the left grip position is used to evaluate a closest point on the bending path. This interpolation value of this point on the path is used to update the current blend shape animation of the tube(We utilized blend shape animation for the tube bending transition, with considerations from the findings in one of our previous blog). During this process, the disabled left grip collider is also mapped to the closest point from left grip to the path, and ready to be re-enable for grip detection in case the player some how loose any of the grips. 

The above implementation, together with our progress last week, give us an prototype on the tube handling in Neon Atelier, and an solid workflow to scale up for more detailed missions. Still there is distance from an concrete demo though, as the prototype still requires testing and adjustment on an actual VR device.

We are look forward to releasing more updates soon. Thank you very much :)  

_

https://docs.unity3d.com/Packages/com.unity.splines@2.8/manual/index.html

https://docs.unity3d.com/Packages/com.unity.splines@2.8/api/UnityEngine.Splines.SplineUtility.html