Skip to content

Instantly share code, notes, and snippets.

@PopupAsylum
Created September 23, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PopupAsylum/e0613bee39e91f74ebaa821a9c5fac9a to your computer and use it in GitHub Desktop.
Save PopupAsylum/e0613bee39e91f74ebaa821a9c5fac9a to your computer and use it in GitHub Desktop.
A behaviour that makes a rigidbody act like a conveyor, moving rigidbodies that collide with it without moving itself
using UnityEngine;
using System.Collections;
public class ConveyorBelt : MonoBehaviour {
public float speed = 2.0f;
void FixedUpdate()
{
Rigidbody rigidbody = GetComponent<Rigidbody>();
rigidbody.position -= transform.forward * speed * Time.deltaTime;
rigidbody.MovePosition (rigidbody.position + transform.forward * speed * Time.deltaTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment