informa
1 MIN READ
Blogs

Easy Conveyor Belt Physics in Unity

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

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.

Latest Jobs

Manticore Games

San Mateo, California
8.23.22
Senior Software Engineer - Mobile

Sony PlayStation

San Diego, California
6.23.22
Sr. Online Programmer

The Walt Disney Company

Glendale, California
8.1.22
Associate Marketing Manager - Walt Disney Games

Insomniac Games

Burbank, California
8.26.22
Accessibility Design Researcher
More Jobs   

CONNECT WITH US

Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more