Skip to content
Snippets Groups Projects
Commit aa8d1333 authored by Julian Grothoff's avatar Julian Grothoff
Browse files

Added shift functionality

parent 170732b4
No related branches found
No related tags found
No related merge requests found
{"count":1,"self":41.5480704,"total":43.569997,"children":{"AgentSendState":{"count":2156,"self":0.9729009999999999,"total":1.829478,"children":{"CollectObservations":{"count":27692,"self":0.46948199999999995,"total":0.46948199999999995,"children":null},"CollectDiscreteActionMasks":{"count":27692,"self":0.38709499999999997,"total":0.38709499999999997,"children":null}}},"DecideAction":{"count":2156,"self":0.034943999999999996,"total":0.034943999999999996,"children":null},"AgentAct":{"count":2156,"self":0.156192,"total":0.156192,"children":null}},"gauges":{"PTSLearning.CumulativeReward":{"count":58,"max":10.62,"min":-10,"value":-10,"weightedAverage":-5.49245453}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1587290712","unity_version":"2019.3.9f1","command_line_arguments":"\/Applications\/Unity\/Hub\/Editor\/2019.3.9f1\/Unity.app\/Contents\/MacOS\/Unity -projectpath \/Users\/anjavogel\/Downloads\/PTSControl\/PTSSim -useHub -hubIPC -cloudEnvironment production -hubSessionId e56de7b0-7c29-11ea-bdb9-af8339fc51bf -accessToken irHPe69LhSmjG2xdSMEwvjGrV0ugLwNGPoDzOdX-j-k008f","communication_protocol_version":"0.16.0","com.unity.ml-agents_version":"0.15.1-preview","scene_name":"PTS","end_time_seconds":"1587290756"}} {"count":1,"self":6.2360831999999995,"total":6.318222,"children":{"AgentSendState":{"count":290,"self":0.041204,"total":0.071311,"children":{"CollectObservations":{"count":813,"self":0.018674,"total":0.018674,"children":null},"CollectDiscreteActionMasks":{"count":813,"self":0.011432999999999999,"total":0.011432999999999999,"children":null}}},"DecideAction":{"count":290,"self":0.004354,"total":0.004354,"children":null},"AgentAct":{"count":290,"self":0.005121,"total":0.005121,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1587326809","unity_version":"2019.3.9f1","command_line_arguments":"\/Applications\/Unity\/Hub\/Editor\/2019.3.9f1\/Unity.app\/Contents\/MacOS\/Unity -projectpath \/Users\/anjavogel\/Downloads\/PTSControl\/PTSSim -useHub -hubIPC -cloudEnvironment production -hubSessionId e56de7b0-7c29-11ea-bdb9-af8339fc51bf -accessToken irHPe69LhSmjG2xdSMEwvjGrV0ugLwNGPoDzOdX-j-k008f","communication_protocol_version":"0.16.0","com.unity.ml-agents_version":"0.15.1-preview","scene_name":"PTS","end_time_seconds":"1587326815"}}
\ No newline at end of file \ No newline at end of file
...@@ -27,9 +27,9 @@ Transform: ...@@ -27,9 +27,9 @@ Transform:
m_LocalPosition: {x: 4, y: 0, z: 0} m_LocalPosition: {x: 4, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 2548727115264289735}
- {fileID: 2548727114722773623}
- {fileID: 2548727115584885804} - {fileID: 2548727115584885804}
- {fileID: 2548727114722773623}
- {fileID: 2548727115264289735}
m_Father: {fileID: 169174050895113485} m_Father: {fileID: 169174050895113485}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -60,13 +60,13 @@ Transform: ...@@ -60,13 +60,13 @@ Transform:
m_LocalPosition: {x: -6, y: 0, z: -2} m_LocalPosition: {x: -6, y: 0, z: -2}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 2974164015980282896} - {fileID: 2548727115397850182}
- {fileID: 2548727115695240154} - {fileID: 3085233459863993800}
- {fileID: 169174050350383489} - {fileID: 169174050350383489}
- {fileID: 169174051606608431} - {fileID: 169174051606608431}
- {fileID: 169174052109479086} - {fileID: 169174052109479086}
- {fileID: 3085233459863993800} - {fileID: 2548727115695240154}
- {fileID: 2548727115397850182} - {fileID: 2974164015980282896}
m_Father: {fileID: 6844626074183280644} m_Father: {fileID: 6844626074183280644}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -85,7 +85,7 @@ GameObject: ...@@ -85,7 +85,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!4 &169174051606608431 --- !u!4 &169174051606608431
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -97,9 +97,9 @@ Transform: ...@@ -97,9 +97,9 @@ Transform:
m_LocalPosition: {x: 4, y: 0, z: 2} m_LocalPosition: {x: 4, y: 0, z: 2}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 2548727114316569630}
- {fileID: 2548727116207330711}
- {fileID: 2548727115423843865} - {fileID: 2548727115423843865}
- {fileID: 2548727116207330711}
- {fileID: 2548727114316569630}
m_Father: {fileID: 169174050895113485} m_Father: {fileID: 169174050895113485}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -118,7 +118,7 @@ GameObject: ...@@ -118,7 +118,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!4 &169174052109479086 --- !u!4 &169174052109479086
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -130,9 +130,9 @@ Transform: ...@@ -130,9 +130,9 @@ Transform:
m_LocalPosition: {x: 4, y: 0, z: 4} m_LocalPosition: {x: 4, y: 0, z: 4}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 2548727116313206168}
- {fileID: 6560727524579531145}
- {fileID: 2548727116326960568} - {fileID: 2548727116326960568}
- {fileID: 6560727524579531145}
- {fileID: 2548727116313206168}
m_Father: {fileID: 169174050895113485} m_Father: {fileID: 169174050895113485}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -261,6 +261,8 @@ Transform: ...@@ -261,6 +261,8 @@ Transform:
- {fileID: 169174052277945025} - {fileID: 169174052277945025}
- {fileID: 169174050895113485} - {fileID: 169174050895113485}
- {fileID: 169174050707208121} - {fileID: 169174050707208121}
- {fileID: 6332432346143671051}
- {fileID: 3112591704662025796}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -277,6 +279,7 @@ MonoBehaviour: ...@@ -277,6 +279,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
conveyors: [] conveyors: []
shiftConveyors: []
palettes: [] palettes: []
--- !u!1001 &169174050709379159 --- !u!1001 &169174050709379159
PrefabInstance: PrefabInstance:
...@@ -323,7 +326,7 @@ PrefabInstance: ...@@ -323,7 +326,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 2 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -340,10 +343,20 @@ PrefabInstance: ...@@ -340,10 +343,20 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3}
propertyPath: m_LocalScale.x
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3}
propertyPath: m_LocalScale.y
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: ConveyorEnter value: TransportEntry
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -403,7 +416,7 @@ PrefabInstance: ...@@ -403,7 +416,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 2
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -423,7 +436,7 @@ PrefabInstance: ...@@ -423,7 +436,7 @@ PrefabInstance:
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: ConveyerExit value: TransportExit
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -483,7 +496,7 @@ PrefabInstance: ...@@ -483,7 +496,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 6 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -563,7 +576,7 @@ PrefabInstance: ...@@ -563,7 +576,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 2 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -643,7 +656,7 @@ PrefabInstance: ...@@ -643,7 +656,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 2 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -685,6 +698,21 @@ PrefabInstance: ...@@ -685,6 +698,21 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 169174050895113485} m_TransformParent: {fileID: 169174050895113485}
m_Modifications: m_Modifications:
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.size
value: 3
objectReference: {fileID: 0}
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.data[1]
value: 2
objectReference: {fileID: 0}
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.data[2]
value: 4
objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
...@@ -723,7 +751,7 @@ PrefabInstance: ...@@ -723,7 +751,7 @@ PrefabInstance:
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 5 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
...@@ -803,7 +831,7 @@ PrefabInstance: ...@@ -803,7 +831,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 2
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -883,7 +911,7 @@ PrefabInstance: ...@@ -883,7 +911,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 2
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -963,7 +991,7 @@ PrefabInstance: ...@@ -963,7 +991,7 @@ PrefabInstance:
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 6
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 2380120697141585391, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -1005,6 +1033,21 @@ PrefabInstance: ...@@ -1005,6 +1033,21 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 169174050895113485} m_TransformParent: {fileID: 169174050895113485}
m_Modifications: m_Modifications:
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.size
value: 3
objectReference: {fileID: 0}
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.data[1]
value: 2
objectReference: {fileID: 0}
- target: {fileID: 474371469282999403, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: possiblePositions.Array.data[2]
value: 4
objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
...@@ -1043,7 +1086,7 @@ PrefabInstance: ...@@ -1043,7 +1086,7 @@ PrefabInstance:
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 1 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
...@@ -1060,6 +1103,16 @@ PrefabInstance: ...@@ -1060,6 +1103,16 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: m_LocalScale.x
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2921135881381771650, guid: 7a790576c7af54d728611363a86b0e47,
type: 3}
propertyPath: m_LocalScale.y
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 4203960842958611744, guid: 7a790576c7af54d728611363a86b0e47, - target: {fileID: 4203960842958611744, guid: 7a790576c7af54d728611363a86b0e47,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
...@@ -1158,6 +1211,86 @@ Transform: ...@@ -1158,6 +1211,86 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 2917908171107060378} m_PrefabInstance: {fileID: 2917908171107060378}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &3339063132006125152
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 6844626074183280644}
m_Modifications:
- target: {fileID: 767232303689607797, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_BrainParameters.vectorObservationSize
value: 41
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.x
value: 6
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.25
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297391, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_Name
value: Palette (1)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1d9169e55f0cc40c88783fd142df404e, type: 3}
--- !u!4 &6332432346143671051 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
m_PrefabInstance: {fileID: 3339063132006125152}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &3602103055782209745 --- !u!1001 &3602103055782209745
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1238,6 +1371,86 @@ Transform: ...@@ -1238,6 +1371,86 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 3602103055782209745} m_PrefabInstance: {fileID: 3602103055782209745}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &5946379039596309295
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 6844626074183280644}
m_Modifications:
- target: {fileID: 767232303689607797, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_BrainParameters.vectorObservationSize
value: 41
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.x
value: 6
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.25
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8770740007255297391, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
propertyPath: m_Name
value: Palette (2)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1d9169e55f0cc40c88783fd142df404e, type: 3}
--- !u!4 &3112591704662025796 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3}
m_PrefabInstance: {fileID: 5946379039596309295}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &8794265382645742694 --- !u!1001 &8794265382645742694
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1303,7 +1516,7 @@ PrefabInstance: ...@@ -1303,7 +1516,7 @@ PrefabInstance:
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: ConveyorCenter value: TransportCenter
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452, - target: {fileID: 3736139061161015629, guid: fc9690452f32341ef95f0065f7b4a452,
type: 3} type: 3}
...@@ -1338,7 +1551,7 @@ PrefabInstance: ...@@ -1338,7 +1551,7 @@ PrefabInstance:
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e, - target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3} type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: -2 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e, - target: {fileID: 8770740007255297387, guid: 1d9169e55f0cc40c88783fd142df404e,
type: 3} type: 3}
... ...
......
...@@ -108,9 +108,9 @@ MonoBehaviour: ...@@ -108,9 +108,9 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_BrainParameters: m_BrainParameters:
vectorObservationSize: 21 vectorObservationSize: 41
numStackedVectorObservations: 1 numStackedVectorObservations: 1
vectorActionSize: 03000000 vectorActionSize: 050000000300000003000000
vectorActionDescriptions: [] vectorActionDescriptions: []
vectorActionSpaceType: 0 vectorActionSpaceType: 0
m_Model: {fileID: 0} m_Model: {fileID: 0}
...@@ -135,5 +135,5 @@ MonoBehaviour: ...@@ -135,5 +135,5 @@ MonoBehaviour:
maxStep: 0 maxStep: 0
hasUpgradedFromAgentParameters: 1 hasUpgradedFromAgentParameters: 1
maxStep: 0 maxStep: 0
conveyorPosition: {fileID: 0} conveyor: {fileID: 0}
conveyorTarget: {fileID: 0} target: {fileID: 0}
This diff is collapsed.
...@@ -4,17 +4,8 @@ using UnityEngine; ...@@ -4,17 +4,8 @@ using UnityEngine;
public class Conveyor : MonoBehaviour public class Conveyor : MonoBehaviour
{ {
public bool isOccupied = false; [Tooltip("Control occupation.")]
public Palette occupier;
// Start is called before the first frame update public bool IsOccupied { get => occupier != null; }
void Start()
{
}
// Update is called once per frame
void Update()
{
}
} }
...@@ -2,27 +2,38 @@ ...@@ -2,27 +2,38 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using MLAgents; using MLAgents;
using System.Linq;
public class PTS : MonoBehaviour public class PTS : MonoBehaviour
{ {
public Conveyor[] conveyors; public Conveyor[] conveyors;
public ShiftConveyor[] shiftConveyors;
public Palette[] palettes; public Palette[] palettes;
/*
* Reset is called on episodeBegin from Agent
*/
public void Reset(){ public void Reset(){
foreach (Conveyor conveyor in conveyors) foreach (Conveyor conveyor in conveyors)
{ {
// Reset occupation // Reset occupation
conveyor.isOccupied = false; conveyor.occupier = null;
} }
foreach(Palette palette in palettes) foreach (ShiftConveyor shift in shiftConveyors)
{
// Set shift position
shift.SetRandomPosition();
}
// Get random palette positions
int[] randomPositions = Enumerable.Range(0, conveyors.Length - 1).OrderBy(x => System.Guid.NewGuid()).Take(palettes.Length).ToArray();
for (int i = 0; i < palettes.Length; i++)
{ {
// Place palette at random position // Place palette at random position
int palettePos = Random.Range(0, conveyors.Length); palettes[i].transform.position = conveyors[randomPositions[i]].transform.position + Vector3.up * 0.25f; //TODO move to Palette class
palette.transform.position = conveyors[palettePos].transform.position + Vector3.up * 0.2f;
// Pick random target // Set exit as target for all palettes
int target = Random.Range(0, conveyors.Length); palettes[i].target = conveyors[conveyors.Length-1]; // Hopefully this is the Exit
while(target == palettePos)
target = Random.Range(0, conveyors.Length);
palette.conveyorTarget = conveyors[target];
} }
} }
...@@ -31,12 +42,7 @@ public class PTS : MonoBehaviour ...@@ -31,12 +42,7 @@ public class PTS : MonoBehaviour
{ {
conveyors = GetComponentsInChildren<Conveyor>(); conveyors = GetComponentsInChildren<Conveyor>();
palettes = GetComponentsInChildren<Palette>(); palettes = GetComponentsInChildren<Palette>();
shiftConveyors = GetComponentsInChildren<ShiftConveyor>();
Reset(); Reset();
} }
// Update is called once per frame
void Update()
{
}
} }
...@@ -2,18 +2,37 @@ ...@@ -2,18 +2,37 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using MLAgents; using MLAgents;
using System;
public enum PaletteOpMode {BSTATE, left, right, up, down, turn, heat};
public enum ExecutionState {IDLE, EXECUTE};
enum PaletteOpMode {BSTATE, left, right, up, down, turn, heat};
enum ExecutionState {IDLE, EXECUTE};
public class Palette : Agent public class Palette : Agent
{ {
[Tooltip("Current conveyer object.")]
public Conveyor conveyor;
[Tooltip("Target conveyer object.")]
public Conveyor target;
public ExecutionState EXST { get; private set; }
public PaletteOpMode OPMODE { get; private set; }
private PTS pts; private PTS pts;
public Conveyor conveyorPosition;
public Conveyor conveyorTarget;
private float opModeProgress; private float opModeProgress;
private float targetDistance; private float targetDistance;
private ExecutionState EXST;
private PaletteOpMode OPMODE; private static KeyCode[] AlphaNumber = {
KeyCode.Alpha0,
KeyCode.Alpha1,
KeyCode.Alpha2,
KeyCode.Alpha3,
KeyCode.Alpha4,
KeyCode.Alpha5,
KeyCode.Alpha6,
KeyCode.Alpha7,
KeyCode.Alpha8,
KeyCode.Alpha9,
};
/// <summary> /// <summary>
/// Initial setup, called when the agent is enabled /// Initial setup, called when the agent is enabled
...@@ -30,8 +49,14 @@ public class Palette : Agent ...@@ -30,8 +49,14 @@ public class Palette : Agent
public override void OnEpisodeBegin() public override void OnEpisodeBegin()
{ {
pts.Reset(); pts.Reset();
conveyorPosition = getCurrentConveyor(); conveyor = GetCurrentConveyor();
targetDistance = calculateTargetDistance(); while(conveyor == null) //FIXME: Bad detection of conveyer
{
Debug.LogWarning("Need to reset PTS because of bad conveyer detection of palette.");
pts.Reset();
conveyor = GetCurrentConveyor();
}
targetDistance = TargetDistance;
EXST = ExecutionState.IDLE; EXST = ExecutionState.IDLE;
OPMODE = PaletteOpMode.BSTATE; OPMODE = PaletteOpMode.BSTATE;
...@@ -46,11 +71,19 @@ public class Palette : Agent ...@@ -46,11 +71,19 @@ public class Palette : Agent
/// Behavior Type to "Heuristic Only" in the Behavior Parameters inspector. /// Behavior Type to "Heuristic Only" in the Behavior Parameters inspector.
/// </summary> /// </summary>
/// <returns>A vectorAction array of floats that will be passed into <see cref="AgentAction(float[])"/></returns> /// <returns>A vectorAction array of floats that will be passed into <see cref="AgentAction(float[])"/></returns>
public override float[] Heuristic() public override float[] Heuristic()
{ {
PaletteOpMode opMode = PaletteOpMode.BSTATE; PaletteOpMode opMode = PaletteOpMode.BSTATE;
float[] actions = new float[pts.shiftConveyors.Length+1];
// Reset
if (Input.GetKey(KeyCode.R))
{
EndEpisode();
return actions;
}
// Move pallette
if (Input.GetKey(KeyCode.W)) if (Input.GetKey(KeyCode.W))
{ {
opMode = PaletteOpMode.up; opMode = PaletteOpMode.up;
...@@ -75,23 +108,45 @@ public class Palette : Agent ...@@ -75,23 +108,45 @@ public class Palette : Agent
{ {
opMode = PaletteOpMode.heat; opMode = PaletteOpMode.heat;
} }
actions[0] = (float)opMode;
// Put the actions into an array and return // Move shifts
return new float[] { (float) opMode }; for (int i = 1; i < actions.Length && i < 10; i++)
{
if (Input.GetKey(AlphaNumber[i]))
{
if (Input.GetKey(KeyCode.UpArrow))
actions[i] = 1;
else if (Input.GetKey(KeyCode.DownArrow))
actions[i] = 2;
else
actions[i] = 0;
}
}
return actions;
} }
/// <summary> /// <summary>
/// Perform actions based on a vector of numbers /// Perform actions based on a vector of numbers
/// </summary> /// </summary>
/// <param name="vectorAction">The list of actions to take</param> /// <param name="actions">The list of actions to take</param>
public override void OnActionReceived(float[] actions)
public override void OnActionReceived(float[] vectorAction)
{ {
// Apply a tiny negative reward every step to encourage action // Apply a tiny negative reward every step to encourage action
if (maxStep > 0) AddReward(-1f / maxStep); if (maxStep > 0) AddReward(-1f / maxStep);
// Execute an operation mode // Execute palette action
ExecuteOpMode((PaletteOpMode)vectorAction[0]); ExecuteOpMode((PaletteOpMode)actions[0]);
// Execute shift actions
for (int i = 1; i < actions.Length; i++)
{
if (actions[i] == 1)
ExecuteShift(i - 1, true);
else if (actions[i] == 2)
ExecuteShift(i - 1, false);
}
} }
/// <summary> /// <summary>
...@@ -102,19 +157,19 @@ public class Palette : Agent ...@@ -102,19 +157,19 @@ public class Palette : Agent
//TODO mask possible actions: https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Design-Agents.md#masking-discrete-actions //TODO mask possible actions: https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Design-Agents.md#masking-discrete-actions
// Occupation states of conveyors // Occupation states of conveyors
foreach(Conveyor conveyor in pts.conveyors) foreach(Conveyor conveyor in pts.conveyors)
sensor.AddObservation(conveyor.isOccupied); {
sensor.AddObservation(conveyor.IsOccupied);
}
// Current position // Current position
sensor.AddOneHotObservation(System.Array.IndexOf(pts.conveyors, conveyorPosition), pts.conveyors.Length); sensor.AddOneHotObservation(System.Array.IndexOf(pts.conveyors, conveyor), pts.conveyors.Length);
// Target position // Target position
sensor.AddOneHotObservation(System.Array.IndexOf(pts.conveyors, conveyorTarget), pts.conveyors.Length); sensor.AddOneHotObservation(System.Array.IndexOf(pts.conveyors, target), pts.conveyors.Length);
// Shift positions
// --> State Space is 3 times active conveyor count foreach (ShiftConveyor shift in pts.shiftConveyors)
}
// Start is called before the first frame update
void Start()
{ {
sensor.AddObservation(shift.Position);
}
// --> State Space is 3 times active conveyor count + count of shift conveyors
} }
// Update is called once per frame // Update is called once per frame
...@@ -129,33 +184,23 @@ public class Palette : Agent ...@@ -129,33 +184,23 @@ public class Palette : Agent
/// <param name="opMode">The operation mode to execute in palette</param> /// <param name="opMode">The operation mode to execute in palette</param>
private void ExecuteOpMode(PaletteOpMode opMode) private void ExecuteOpMode(PaletteOpMode opMode)
{ {
if (opMode == PaletteOpMode.BSTATE)
return;
// Select new OpMode // Select new OpMode
if(opMode != PaletteOpMode.BSTATE && if (OPMODE == PaletteOpMode.BSTATE &&
OPMODE == PaletteOpMode.BSTATE &&
EXST == ExecutionState.IDLE) EXST == ExecutionState.IDLE)
{ {
Debug.Log("Selected operation mode: " + opMode);
OPMODE = opMode; OPMODE = opMode;
EXST = ExecutionState.EXECUTE; EXST = ExecutionState.EXECUTE;
opModeProgress = 0; opModeProgress = 0;
// Reward for selecting an opmode
AddReward(0.1f); AddReward(0.1f);
}
// Simulate opMode execution
if(OPMODE == PaletteOpMode.BSTATE)
return;
else if(OPMODE == PaletteOpMode.right)
{
opModeProgress += Time.deltaTime/2f;
transform.Translate(-Time.deltaTime, 0, 0);
}
else if(OPMODE == PaletteOpMode.left)
{
opModeProgress += Time.deltaTime/2f;
transform.Translate(Time.deltaTime, 0, 0);
}else {
// Not implemented yet
opModeProgress = 1;
} }
SimulateOperationMode();
// Check if opMode simulation is completed // Check if opMode simulation is completed
if (opModeProgress >= 1) if (opModeProgress >= 1)
...@@ -166,53 +211,158 @@ public class Palette : Agent ...@@ -166,53 +211,158 @@ public class Palette : Agent
opModeProgress = 0; opModeProgress = 0;
// Simulate the update of the postion // Simulate the update of the postion
conveyorPosition.isOccupied = false; conveyor.occupier = null;
conveyorPosition = getCurrentConveyor(); conveyor = GetCurrentConveyor();
if(conveyorPosition == null) if(conveyor == null)
{ {
SetReward(-10f); SetReward(-10f);
EndEpisode(); EndEpisode();
return;
} }
//Snap to exact conveyor position
transform.position = conveyor.transform.position + (Vector3.up * 0.25f);
// Check if target is reached // Check if target is reached
if(conveyorPosition == conveyorTarget) if (conveyor == target)
{ {
SetReward(10f); AddReward(10f);
EndEpisode(); EndEpisode();
}else{ }else{
// Add reward if closer to target // Add reward if closer to target
float newTargetDistance = calculateTargetDistance(); float newTargetDistance = TargetDistance;
AddReward((targetDistance - newTargetDistance) > 0 ? -0.01f : 0.01f); AddReward((targetDistance - newTargetDistance) > 0 ? -0.01f : 0.01f);
targetDistance = calculateTargetDistance(); targetDistance = TargetDistance;
} }
} }
// Negative reward for illegal opMode // Negative reward for illegal opMode
if(opModeProgress == -1) else if (opModeProgress == -1)
{ {
AddReward(-0.1f); // Simulate update of states
} OPMODE = PaletteOpMode.BSTATE;
EXST = ExecutionState.IDLE;
opModeProgress = 0;
// Compensate reward and punish for choosing unnecessary operation mode
AddReward(-0.2f);
}
} }
private float calculateTargetDistance(){ private float TargetDistance
return Vector3.Distance(conveyorPosition.transform.position, conveyorTarget.transform.position); {
get
{
if (conveyor != null && target != null)
return Vector3.Distance(conveyor.transform.position, target.transform.position);
return float.MaxValue;
}
} }
private Conveyor getCurrentConveyor() private Conveyor GetCurrentConveyor()
{ {
Collider[] hitColliders = Physics.OverlapSphere(gameObject.transform.position + 0 * Vector3.down, transform.localScale.y / 2f); Collider[] hitColliders = Physics.OverlapSphere(gameObject.transform.position + 0.2f * Vector3.down, transform.localScale.y / 2f);
if(hitColliders.Length < 1) if(hitColliders.Length < 1)
return null; return null;
foreach (Collider collider in hitColliders){ foreach (Collider collider in hitColliders){
if (collider.transform.CompareTag("Conveyor")) if (collider.transform.CompareTag("Conveyor"))
{ {
Debug.Log(name + " positioned on Conveyor: " + collider.name);
Conveyor conveyor = collider.gameObject.GetComponent<Conveyor>(); Conveyor conveyor = collider.gameObject.GetComponent<Conveyor>();
conveyor.isOccupied = true; conveyor.occupier = this;
return conveyor;
}
}
return null;
}
private Conveyor GetNextConveyor(bool directionRight)
{
Collider[] hitColliders = Physics.OverlapSphere(
transform.position + 0.2f * Vector3.down + 2f * (directionRight ? Vector3.left : Vector3.right),
transform.localScale.y / 2f);
if (hitColliders.Length < 1)
return null;
foreach (Collider collider in hitColliders)
{
if (collider.transform.CompareTag("Conveyor"))
{
Conveyor conveyor = collider.gameObject.GetComponent<Conveyor>();
conveyor.occupier = this;
return conveyor; return conveyor;
} }
} }
return null; return null;
} }
private void SimulateOperationMode()
{
// Simulate operation mode
if (OPMODE == PaletteOpMode.BSTATE)
return;
else if (OPMODE == PaletteOpMode.right || OPMODE == PaletteOpMode.left)
{
// Occupy next conveyor first
if(opModeProgress == 0)
{
Conveyor nextConveyor = GetNextConveyor(OPMODE == PaletteOpMode.right);
if (nextConveyor == null || nextConveyor.occupier != this)
{
opModeProgress = -1;
return;
}
nextConveyor.occupier = this;
}
// Move left or right
opModeProgress += Time.deltaTime / 2f;
transform.Translate(OPMODE == PaletteOpMode.right ? -Time.deltaTime : Time.deltaTime, 0, 0);
}
else if (OPMODE == PaletteOpMode.up || OPMODE == PaletteOpMode.down)
{
if (conveyor.TryGetComponent(out ShiftConveyor shift))
{
opModeProgress = shift.Shift(OPMODE == PaletteOpMode.up);
transform.position = new Vector3(
transform.position.x,
transform.position.y,
shift.transform.position.z);
}
else
// Palette is not on a shift conveyor
opModeProgress = -1;
}
else
{
// Not implemented yet or not possible
opModeProgress = -1;
}
}
private void ExecuteShift(int shiftNumber, bool directionUp)
{
Conveyor conveyor = pts.shiftConveyors[shiftNumber].GetComponent<Conveyor>();
if (!conveyor.IsOccupied)
{
StartCoroutine(SimulateShift(conveyor, pts.shiftConveyors[shiftNumber], directionUp));
}
else
{
return;
}
}
private IEnumerator SimulateShift(Conveyor conveyor, ShiftConveyor shift, bool directionUp)
{
// Occupy shift
conveyor.occupier = this;
// Shift up or down
float progress = 0;
while(progress < 1)
{
progress = shift.Shift(directionUp);
if (progress == -1)
break;
yield return null;
}
// Free shift
conveyor.occupier = null;
}
} }
...@@ -2,19 +2,58 @@ ...@@ -2,19 +2,58 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// Todo make generic shifter, that can shift (and rotate) to different positions (and roations)
public class ShiftConveyor : MonoBehaviour public class ShiftConveyor : MonoBehaviour
{ {
[Tooltip("Current position (index of possiblePositions starting from 0)")]
private int _position;
public int Position
{
get { return _position; }
set { if(value >= 0 && value < possiblePositions.Count)
transform.localPosition = new Vector3(
transform.localPosition.x,
transform.localPosition.y,
possiblePositions[value]);
_position = value;
}
}
[Tooltip("Speed of the shift movement.")]
public float shiftSpeed = 1f;
[Tooltip("Moves the shift to the exact position, if distance is smaller than value")]
public float snapToTarget = 0.01f;
public int shiftPos = -1; [Tooltip("Z value for each possible shift position (have to be ordered by size).")]
// Todo order on set accessor
public List<float> possiblePositions;
// Start is called before the first frame update
void Start() public float Shift(bool directionUp)
{
// Check if direction is possible
if (Position == -1
|| (directionUp && Position == 0)
|| (!directionUp && Position == possiblePositions.Count - 1))
{ {
return -1;
}
// Move into direction
transform.Translate(0, 0, Time.deltaTime * shiftSpeed * (directionUp? -1 : 1));
// Check distance to target
int targetPosition = Position + (directionUp ? -1 : 1);
float distance = System.Math.Abs(transform.localPosition.z - possiblePositions[targetPosition]);
if (distance <= snapToTarget)
{
Position = targetPosition;
return 1;
}
return 1 - (distance / (System.Math.Abs(possiblePositions[targetPosition] - possiblePositions[Position])));
} }
// Update is called once per frame public void SetRandomPosition()
void Update()
{ {
Position = Random.Range(0, possiblePositions.Count);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment