/// <summary>
/// 传送带 直线传送带
/// </summary>
public class ConveyerBelt : MonoBehaviour
{
public float Speed = 1;
protected float mspeed;
protected Vector3 direction;
protected Rigidbody rd;
List<GameObject> Goods = new List<GameObject>();
protected virtual void Start()
{
mspeed = Speed;
direction = transform.right;
rd = GetComponent<Rigidbody>();
}
protected virtual void FixedUpdate()
{
Vector3 pos = rd.position;
rd.position -= direction * mspeed * Time.fixedDeltaTime;
rd.MovePosition(pos);
}
}
注意:传送带Rigidbody 的isKinematic要设置为true。
同样,想要带动货物旋转,也得需要调用rd.MoveRotation,直接改变re.Rotation并不能产生摩擦力。
讲解视频在这Unity 模拟传输机_哔哩哔哩_bilibili。具体原理暂时没搞明白。是MovePosition可以触发摩擦力吗?有明白的大佬欢迎指点。