groundWidth = 100;
groundHight = 100;
conveyorWidth = 24;
boxWidth = 15;

offset0 = -25;
offset1 = 0;
offset2 = 25;
offset3 = 50;
offset4 = 75;
offset5 = 100;
boxOffset = -10;

Dynamic[
Animate[
(*いろいろな計算*)

If[(t<50 && offset1  < 0),{                                                                                                                                                                                               (*リセット(t==0だとスルーされるときもあったので条件を大きめに設定している)*)
offset0 = -25;
offset1 = 0;
offset2 = 25;
offset3 = 50;
offset4 = 75;
offset5 = 100;
boxOffset = -10;

} ];

ground ={White,Polygon[{{0,0,0},{groundWidth,0, 0},{groundWidth,groundHight,0}, {0,groundHight,0}}]};     (*地面*)
(*オフセット計算0*)
If[offset0 +t > groundWidth, offset0  = offset0 - groundWidth - conveyorWidth];                                                                         (*長方形全体がはみ出ていないかチェック*)
offset0L = Which[                                                                                                                                                                                                                        (*長方形の左側のx座標*)
(t+offset0 < 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset0 ≥ 0 && t+offset0 ≤ groundWidth)                                                 ,offset0+t                                                                          (*長方形の左端のx座標*)
]; 
offset0R = Which[                                                                                                                                                                                                                        (*長方形の右端のx座標*)
(offset0L≤ groundWidth && offset0L+conveyorWidth > groundWidth)  , groundWidth,                                                                   (*右端が範囲外の時100*)
(offset0L+conveyorWidth ≤  groundWidth)                                                            ,offset0+t+conveyorWidth                                       (*左端+10で動かす*)
];

(*オフセット計算1*)
If[offset1 +t > groundWidth, offset1  = offset1- groundWidth - conveyorWidth];                                                                         (*長方形全体がはみ出ていないかチェック*)
offset1L = Which[                                                                                                                                                                                                                        (*長方形の左側のx座標*)
(t+offset1 < 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset1≥ 0 && t+offset1 ≤ groundWidth)                                                 ,offset1+t                                                                          (*長方形の左端のx座標*)
]; 
offset1R = Which[                                                                                                                                                                                                                        (*長方形の右端のx座標*)
(offset1L≤ groundWidth && offset1L+conveyorWidth > groundWidth)  , groundWidth,                                                                   (*右端が範囲外の時100*)
(offset1L+conveyorWidth ≤  groundWidth)                                                            ,offset1+t+conveyorWidth                                       (*左端+10で動かす*)
];


(*オフセット計算2*)
If[offset2 +t > groundWidth, offset2 = offset2 - groundWidth - conveyorWidth];                                                                         (*長方形全体がはみ出ていないかチェック*)
offset2L = Which[                                                                                                                                                                                                                        (*長方形の左側のx座標*)
(t+offset2 < 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset2 ≥ 0 && t+offset2 ≤ groundWidth)                                                 ,offset2+t                                                                          (*長方形の左端のx座標*)
]; 
offset2R = Which[                                                                                                                                                                                                                        (*長方形の右端のx座標*)
(offset2L≤ groundWidth && offset2L+conveyorWidth > groundWidth)  , groundWidth,                                                                   (*右端が範囲外の時100*)
(offset2L+conveyorWidth ≤  groundWidth)                                                            ,offset2+t+conveyorWidth                                       (*左端+10で動かす*)
];

(*オフセット計算3*)
If[offset3 +t > groundWidth, offset3 = offset3- groundWidth - conveyorWidth];                                                                         (*長方形全体がはみ出ていないかチェック*)
offset3L = Which[                                                                                                                                                                                                                        (*長方形の左側のx座標*)
(t+offset3 < 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset3≥ 0 && t+offset3 ≤ groundWidth)                                                 ,offset3+t                                                                          (*長方形の左端のx座標*)
]; 
offset3R = Which[                                                                                                                                                                                                                        (*長方形の右端のx座標*)
(offset3L≤ groundWidth && offset3L+conveyorWidth > groundWidth)  , groundWidth,                                                                   (*右端が範囲外の時100*)
(offset3L+conveyorWidth ≤  groundWidth)                                                            ,offset3+t+conveyorWidth                                       (*左端+10で動かす*)
];


(*オフセット計算4*)
If[offset4 +t > groundWidth, offset4  = offset4 - groundWidth - conveyorWidth];                                                                         (*長方形全体がはみ出ていないかチェック*)
offset4L = Which[                                                                                                                                                                                                                        (*長方形の左側のx座標*)
(t+offset4 < 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset4 ≥ 0 && t+offset4 ≤ groundWidth)                                                 ,offset4+t                                                                          (*長方形の左端のx座標*)
]; 
offset4R = Which[                                                                                                                                                                                                                        (*長方形の右端のx座標*)
(offset4L≤ groundWidth && offset4L+conveyorWidth > groundWidth)  , groundWidth,                                                                   (*右端が範囲外の時100*)
(offset4L+conveyorWidth ≤  groundWidth)                                                            ,offset4+t+conveyorWidth                                       (*左端+10で動かす*)
];

(*オフセット計算5*)
If[offset5+t > groundWidth, offset5  = offset5- groundWidth - conveyorWidth];                                                                          (*長方形全体がはみ出ていないかチェック*)
offset5L = Which[                                                                                                                                                                                                                       (*長方形の左側のx座標*)
(t+offset5< 0)                                                                                                                 ,0,                                                                                          (*左端が範囲外の時0*)
(t+offset5≥ 0 && t+offset5 ≤ groundWidth)                                                 ,offset5+t                                                                         (*長方形の左端のx座標*)
]; 
offset5R = Which[                                                                                                                                                                                                                      (*長方形の右端のx座標*)
(offset5L≤ groundWidth && offset5L+conveyorWidth > groundWidth)  , groundWidth,                                                                 (*右端が範囲外の時100*)
(offset5L+conveyorWidth ≤  groundWidth)                                                            ,offset5+t+conveyorWidth                                     (*左端+10で動かす*)
];


(*立方体オフセット計算*)
If[boxOffset +t > groundWidth, boxOffset  = boxOffset - groundWidth - boxWidth];                                                                      (*立方体全体がはみ出ていないかチェック*)

boxOffsetL = Which[                                                                                                                                                                                                                  (*立方体の左側のx座標*)
(t ≤ 10)                                                                                                                                   ,0,                                                                                         (*左端が範囲外の時0*)
(t>10 && t< 50)                                                                                                               ,boxOffset+t ,
(t≥50 && t< 150)                                                                                                             ,20Sin[((t-50)/50)*Pi /2]+50,
( t ≥ 150)                                                                                                                                ,50+(t-150)                                                                  (*立方体の左端のx座標*)
]; 
boxOffsetR = Which[                                                                                                                                                                                                                (*立方体の左側のx座標*)
( t< 50)                                                                                                                                   ,boxOffset+t + boxWidth ,
(t≥50 && t< 150)                                                                                                             ,20Sin[((t-50)/50)*Pi /2]+50+boxWidth,
( t ≥ 150 && 50+(t-150)+boxWidth < groundWidth)                                    ,50+(t-150)+boxWidth,                                       (*立方体の左端のx座標*)
(t ≥  150)                                                                                                                                 ,groundWidth
]; 


boxY = Which[
( t< 50)                                                                                                                                   ,10 ,
(t≥50 && t< 150)                                                                                                             ,42-30Cos[((t-50)/50)*Pi /2],
(t ≥  150)                                                                                                                                 ,75
];

boxZ = Which[
( t< 50)                                                                                                                                   ,0,
(t≥50 && t< 150)                                                                                                             ,5,
(t ≥  150)                                                                                                                                 ,0
];

box    = {Yellow,Cuboid[{boxOffsetL,boxY,boxZ}, {boxOffsetR, boxY+boxWidth,boxZ+boxWidth}]};


aCon0={LightGray,Polygon[{{offset0L,5,1},{offset0L,30,1},{offset0R,30,1}, {offset0R,5,1}}]};
bCon0={LightGray,Polygon[{{offset0L,70,1},{offset0L,95,1},{offset0R,95,1}, {offset0R,70,1}}]};
aCon1={LightGray,Polygon[{{offset1L,5,1},{offset1L,30,1},{offset1R,30,1}, {offset1R,5,1}}]};
bCon1={LightGray,Polygon[{{offset1L,70,1},{offset1L,95,1},{offset1R,95,1}, {offset1R,70,1}}]};
aCon2={LightGray,Polygon[{{offset2L,5,1},{offset2L,30,1},{offset2R,30,1}, {offset2R,5,1}}]};
bCon2={LightGray,Polygon[{{offset2L,70,1},{offset2L,95,1},{offset2R,95,1}, {offset2R,70,1}}]};
aCon3={LightGray,Polygon[{{offset3L,5,1},{offset3L,30,1},{offset3R,30,1}, {offset3R,5,1}}]};
bCon3={LightGray,Polygon[{{offset3L,70,1},{offset3L,95,1},{offset3R,95,1}, {offset3R,70,1}}]};
aCon4={LightGray,Polygon[{{offset4L,5,1},{offset4L,30,1},{offset4R,30,1}, {offset4R,5,1}}]};
bCon4={LightGray,Polygon[{{offset4L,70,1},{offset4L,95,1},{offset4R,95,1}, {offset4R,70,1}}]};
aCon5={LightGray,Polygon[{{offset5L,5,1},{offset5L,30,1},{offset5R,30,1}, {offset5R,5,1}}]};
bCon5={LightGray,Polygon[{{offset5L,70,1},{offset5L,95,1},{offset5R,95,1}, {offset5R,70,1}}]};


T=Which[
( t< 50),
 {CapForm["Butt"],Tube[{{50,50,0},{50,50,20},{50,15,30},{50,15,20}},2]} ,
(t≥50 && t< 150),
{CapForm["Butt"],Tube[{{50,50,0},{50,50,20},{20Sin[((t-50)/50)*Pi /2]+57.5,42-30Cos[((t-50)/50)*Pi /2]+7.5,30},{20Sin[((t-50)/50)*Pi /2]+57.5,42-30Cos[((t-50)/50)*Pi /2]+7.5,20}},2]},
(t ≥  150),
{CapForm["Butt"],Tube[{{50,50,0},{50,50,20},{50,85,30},{50,85,20}},2]}
];

Graphics3D[{ground,aCon0,aCon1,aCon2,aCon3,aCon4,aCon5, bCon0,bCon1, bCon2,bCon3,bCon4, bCon5,T,box}
],
{t,0,200},
{AnimationRepetitions->Infinity}
]
]