Created
September 23, 2016 10:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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