Sponsored By

Easy Conveyor Belt Physics in Unity

Implementing easy, simple, realistic and easy conveyor belt physics in unity

Mark Hogan, Blogger

November 3, 2014

1 Min Read
Game Developer logo in a gray background | Game Developer

Originally posted on popupasylum.co.uk

This is just a quick blog about how I've ended up implementing conveyor belt physics. I googled it and found many answers but many of the solutions involved rollers or applying forces to objects in OnCollisionStay() but these didn't have the look and feel that I expected given how conveyors work, the objects appear frictionless and didnt take the point of collision into account, and I thought the roller option might end up being pretty heavy and had issues with spheres getting stuck between rollers.

My solution is very, VERY simple but works great. I have a box collider with a kinematic rigidbody, then in the fixed update loop I move the rigidbody backwards by setting rigidbody.position, by setting the position directly its as if the object is teleported and objects that are touching it dont inherit any additional velocity. I then use MovePosition() to move it forwards, putting it back where it started, but this time with all the physics reactions you'd expect. This combination results in the actual conveyor belt object not moving but all objects colliding with it acting as if it was moving forwards.

Here's the script, its easy to see how simple it is;

using UnityEngine;
using System.Collections;

public class ConveyorBelt : MonoBehaviour {

    public float speed = 2.0f;

    void FixedUpdate()
    {
        rigidbody.position -= transform.forward * speed * Time.deltaTime;
        rigidbody.MovePosition (rigidbody.position + transform.forward * speed * Time.deltaTime);

    }

}

I've put a webplayer demo on the Popup Asylum Blog to show it in action. The result is very natural looking, and particularly how friction is applied helps bring a higher level of realism to the physics.

Read more about:

Blogs

About the Author

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like