DEV Community

Piler
Piler

Posted on

[Unity] How to create a conveyor?

Image description

public class Conveyor : MonoBehaviour
{
    public float speed = 1f;
    Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        Vector3 pos = rb.position;
        rb.position += -transform.forward * speed * Time.fixedDeltaTime;
        rb.MovePosition(pos);
    }
}
Enter fullscreen mode Exit fullscreen mode

Reference: https://www.youtube.com/watch?v=hC1QZ0h4oco

Top comments (0)