Friday, August 07, 2015

Conveyor belt physics and UV tricks


I had a bit of a problem making a secure and fully functional conveyor belt line that moves any objects on top of it towards one direction at a certain speed, regardless of the object's mass. It should also do so with multiple stacked objects and dynamic moving objects such as the player character.

My personal struggle of scripting a conveyor belt

   I tried to put all objects on top of the belt into a list, and move all of the objects in different ways, but the result was always too chaotic. After hours of headache and frustration, I found the solution which was very simple and peculiar.



Basically all you have to do is move the actual rigidbody transform of the conveyor belt backwards, and then forward with MovePosition the same amount, during the same frame. So the belt actually takes one step back and then immediately one forward, but everything that cares about the physical world will only be affected by the latter, so all the objects on the line are pushed forward nice and smooth. No need for lists, triggers or collision detections!

Do this every physics step and you're all set (the conveyor belt rigidbody object):
rigidbody.position -= transform.forward * speed * Time.deltaTime;
rigidbody.MovePosition (rigidbody.position + transform.forward * speed * Time.deltaTime);

Thanks Mr. Hogan, and thank you Google as well! The full post can be found here: http://gamasutra.com/blogs/MarkHogan/20141103/229201/Easy_Conveyor_Belt_Physics_in_Unity.php

-Timo Kuronen




The artsy UV tricky side


The conveyor belt is animated using a script which offsets the UV's in sync with rotating gears, which take their speed from the actual belt physics speed controller. So we only need to adjust one value and the animations stay in sync.

Animating the belt with UV offset is the simplest way I could think of and it works pretty much flawlessly. The only downside is the need for a separate texture, but at least it can be kept small and since no geometry is actually moving, lightmapping can be used for the belt.

Looping belt texture

Oh, I also made some other assets which use the uv-offsetting. One can accomplish all sorts of blinking doodads and moving thingamajiggers with this technique. All the screens are animated with uv-offset as well:


As the technique is quite cheap cpu/gpu-wise, we'll be using is for many more things to come.

Thanks for reading!


- Sami Kuronen