|
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:
Thanks!
(comments are locked)
|
|
Because you're already using a Rigidbody, you could use 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.
Thanks for your reply! I experimented with the AddForce method, but with rigidbodies with rectangular shapes just "roll" and bounce on the conveyor belts. I could parent objects to the conveyor belt, but I still don't know how to center them over the z-axis, especially smoothly over time.
Dec 22 '10 at 07:31 PM
CPUFreak91
well, because children apply their transform relative to their parents, if the rigidbodies transform z value is 0, it will be centered on its parents z axis. As for smoothing it, you could find the vectors for where its velocity will be taking it and where you would truly want it to be, and then Lerp() them and apply that result. Possibly. I'm not the best at smoothing things.
Dec 22 '10 at 07:38 PM
Mickydtron
Also, in regards to the rigidbody.AddForce, it should work better for your purposes to say See http://unity3d.com/support/documentation/ScriptReference/ForceMode.html for where I got that from. I believe that this force mode just changes the velocity directly, so you could set the velocity to be whatever you want.
Dec 22 '10 at 07:44 PM
Mickydtron
transform.localPosition is the variable to look for.
Dec 22 '10 at 09:01 PM
Mickydtron
Thanks for your help Mickydtron. I got it to work by parenting and using localPosition. I set the rigidbody's parent to null when it leaves a belt segment in OnCollisionExit() and then if it is colliding with another belt and its parent is null, it will then re-parent to the new belt. This allows the objects to transfer completely to the next belt before it applies a MovePosition which "centers" it enough. Then I can tweak it a bit using transform.localPosition.
Dec 22 '10 at 09:59 PM
CPUFreak91
(comments are locked)
|
|
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
(comments are locked)
|
|
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) { }
(comments are locked)
|


Answers are accepted by chackmarking them, not writing "solved" in the title.