Hi,
I'm trying to make a simple conveyor belt system where the objects on the belts run down the center of the belt. My problem occurs when the object reaches a belt that has a different rotation.
How can I smoothly move an object from one belt to another while getting them to center on a belt's Z-axis?
This is code I'm using to move rigidbodies that collide with the belt:
void OnCollisionStay(Collision collision) { //An object is on the conveyor
if (collision.rigidbody) {
collision.rigidbody.MovePosition(collision.rigidbody.position + collision.transform.InverseTransformDirection(transform.forward) * speed * Time.deltaTime);
}
}
My conveyor setup looks like this:

Thanks!
Because you're already using a Rigidbody, you could use `collision.rigidbody.AddForce(...)` instead of `collision.rigidbody.MovePosition(...)`, and then let the physics engine take care of it.
Alternatively, the conveyer belt could make itself the parent of the rigidbodies that hit it, so that they would then use its transform coordinates. That would force the children objects to align with whatever conveyer they hit last.
`collision.transform.parent = transform;`
I made up a little example project.
I use a low friction physics material (low friction only in one direction like ski's)
It adds forces to the touching objects in the direction of the conveyor.
Fiddle with the conveyor 'physic material' dynamic frictions and the Conveyor components speed variables. The visual scrolling is UV scrolling, this is seperate from the forces applied to the other objects
Get it here http://users.on.net/~edan/cam/visible/Conveyor.zip
Here’s the conveyor belt force operator that worked for me:
//Push on things which collide with this floor
var speed:int = 100;
function OnCollisionStay(collision : Collision) { //An object is on the conveyor
if (collision.rigidbody) {
var tilt : Vector3 = Vector3.right;
var roty = transform.parent.transform.rotation.y;
//Fudged this to get conveyors to push in the right direction
if(roty==0.7071068){
tilt = Vector3.back;
}else if(roty==-0.7071068){
tilt = Vector3.forward;
}else if(roty==0){
tilt = Vector3.right;
}else {
tilt = Vector3.left;
}
//Try other Forcemodes
collision.rigidbody.AddForce(tilt * speed * Time.deltaTime, ForceMode.VelocityChange);
}
}