Skip to content

Commit 3b7fbd3

Browse files
committed
Fix some restart issues on "ConveyorBelt".
1 parent 922a5d0 commit 3b7fbd3

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

LowLevel/Sandbox/Assets/Scenes/Shapes/ConveyorBelt/ConveyorBelt.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ private void SetupOptions()
6767
conveyorSpeed.RegisterValueChangedCallback(evt =>
6868
{
6969
m_ConveyorSpeed = evt.newValue;
70-
71-
// Update the tangent speed.
72-
var surfaceMaterial = m_ConveyorBeltShape.surfaceMaterial;
73-
surfaceMaterial.tangentSpeed = m_ConveyorSpeed;
74-
m_ConveyorBeltShape.surfaceMaterial = surfaceMaterial;
70+
UpdateConveyorSpeed();
7571
});
7672

7773
// Conveyor Angle.
@@ -80,9 +76,7 @@ private void SetupOptions()
8076
conveyorAngle.RegisterValueChangedCallback(evt =>
8177
{
8278
m_ConveyorAngle = evt.newValue;
83-
84-
// Update the conveyor angle.
85-
m_ConveyorBeltBody.rotation = new PhysicsRotate(PhysicsMath.ToRadians(m_ConveyorAngle));
79+
UpdateConveyorAngle();
8680
});
8781

8882
// Spawn.
@@ -119,10 +113,10 @@ private void SetupScene()
119113

120114
// Platform.
121115
{
122-
m_ConveyorBeltBody = m_PhysicsWorld.CreateBody(new PhysicsBodyDefinition { position = Vector2.up * 8f });
116+
m_ConveyorBeltBody = m_PhysicsWorld.CreateBody(new PhysicsBodyDefinition { position = Vector2.up * 8f, rotation = new PhysicsRotate(PhysicsMath.ToRadians(m_ConveyorAngle)) });
123117

124118
var geometry = PolygonGeometry.CreateBox(new Vector2(20f, 0.5f), 0.25f);
125-
var shapeDef = new PhysicsShapeDefinition { surfaceMaterial = new PhysicsShape.SurfaceMaterial { friction = 0.8f, tangentSpeed = 2f } };
119+
var shapeDef = new PhysicsShapeDefinition { surfaceMaterial = new PhysicsShape.SurfaceMaterial { friction = 0.8f, tangentSpeed = m_ConveyorSpeed } };
126120
m_ConveyorBeltShape = m_ConveyorBeltBody.CreateShape(geometry, shapeDef);
127121
}
128122

@@ -146,4 +140,18 @@ private void Spawn(int spawnCount)
146140
body.CreateShape(PolygonGeometry.CreateBox(Vector2.one * scale, radius));
147141
}
148142
}
143+
144+
private void UpdateConveyorAngle()
145+
{
146+
// Update the conveyor angle.
147+
m_ConveyorBeltBody.rotation = new PhysicsRotate(PhysicsMath.ToRadians(m_ConveyorAngle));
148+
}
149+
150+
private void UpdateConveyorSpeed()
151+
{
152+
// Update the tangent speed.
153+
var surfaceMaterial = m_ConveyorBeltShape.surfaceMaterial;
154+
surfaceMaterial.tangentSpeed = m_ConveyorSpeed;
155+
m_ConveyorBeltShape.surfaceMaterial = surfaceMaterial;
156+
}
149157
}

0 commit comments

Comments
 (0)