Skip to content

Commit

Permalink
CarCatching Environment LineRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
colourfulspring committed Feb 23, 2024
1 parent 3ec505b commit c01b72a
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ GameObject:
- component: {fileID: 5601152702967375707}
- component: {fileID: 3822330893343168228}
- component: {fileID: 5628194071647130095}
- component: {fileID: 6387908156284689739}
- component: {fileID: 2645550221542489290}
m_Layer: 2
m_Name: CarAgentGridCollab
m_TagString: blueAgent
Expand All @@ -351,7 +353,7 @@ Transform:
- {fileID: 2704888262008647423}
- {fileID: 2709359580712052713}
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!114 &8110157416270102484
MonoBehaviour:
Expand All @@ -366,7 +368,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 0
VectorObservationSize: 8
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 2
Expand All @@ -375,7 +377,7 @@ MonoBehaviour:
VectorActionDescriptions: []
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 0}
m_Model: {fileID: 5022602860645237092, guid: 3c50cb9026aba7e34955f04c12fa789a, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: Catching
Expand Down Expand Up @@ -463,6 +465,124 @@ BoxCollider:
serializedVersion: 3
m_Size: {x: 45, y: 44, z: 60}
m_Center: {x: 0, y: 0, z: 0}
--- !u!120 &6387908156284689739
LineRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2710286047221272849}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 0
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: af274938e390bf241a2ec6dff21f7b4a, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Positions:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 1}
m_Parameters:
serializedVersion: 3
widthMultiplier: 1
widthCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
colorGradient:
serializedVersion: 2
key0: {r: 1, g: 1, b: 1, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 0
numCapVertices: 0
alignment: 0
textureMode: 0
textureScale: {x: 1, y: 1}
shadowBias: 0.5
generateLightingData: 0
m_MaskInteraction: 0
m_UseWorldSpace: 1
m_Loop: 0
m_ApplyActiveColorSpace: 1
--- !u!114 &2645550221542489290
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2710286047221272849}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: de79dcaa17358444fa44202c1787e270, type: 3}
m_Name:
m_EditorClassIdentifier:
minDistance: 0.1
width: 5
--- !u!1 &2710572731397926669
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,28 @@ MonoBehaviour:
StartingScale: {x: 0, y: 0, z: 0}
DecisionRequester: {fileID: 0}
NavMeshAgent: {fileID: 0}
LineRenderer: {fileID: 0}
- Agent: {fileID: 7246486209573452180}
StartingPos: {x: 0, y: 0, z: 0}
StartingRot: {x: 0, y: 0, z: 0, w: 0}
StartingScale: {x: 0, y: 0, z: 0}
DecisionRequester: {fileID: 0}
NavMeshAgent: {fileID: 0}
LineRenderer: {fileID: 0}
- Agent: {fileID: 3964309580746521657}
StartingPos: {x: 0, y: 0, z: 0}
StartingRot: {x: 0, y: 0, z: 0, w: 0}
StartingScale: {x: 0, y: 0, z: 0}
DecisionRequester: {fileID: 0}
NavMeshAgent: {fileID: 0}
LineRenderer: {fileID: 0}
- Agent: {fileID: 4005891969102443327}
StartingPos: {x: 0, y: 0, z: 0}
StartingRot: {x: 0, y: 0, z: 0, w: 0}
StartingScale: {x: 0, y: 0, z: 0}
DecisionRequester: {fileID: 0}
NavMeshAgent: {fileID: 0}
LineRenderer: {fileID: 0}
UseRandomAgentRotation: 1
UseRandomAgentPosition: 1
ResetTimer: 0
Expand Down Expand Up @@ -406,11 +410,6 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 1581870063183487095}
m_Modifications:
- target: {fileID: 1548337883655231979, guid: a431228058383324287911e110279f5a,
type: 3}
propertyPath: m_ShowGizmos
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2708762399863795223, guid: a431228058383324287911e110279f5a,
type: 3}
propertyPath: m_RootOrder
Expand Down Expand Up @@ -602,6 +601,11 @@ PrefabInstance:
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6387908156284689739, guid: a431228058383324287911e110279f5a,
type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 524edbe6e93be4be3bcce154cad79235, type: 2}
- target: {fileID: 8110157416270102484, guid: a431228058383324287911e110279f5a,
type: 3}
propertyPath: m_Model
Expand Down
19 changes: 11 additions & 8 deletions Project/Assets/ML-Agents/Examples/CarCatching/Scripts/CarAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using UnityEngine.AI;
using Random = UnityEngine.Random;

public class CarAgent : Agent
{
Expand Down Expand Up @@ -58,12 +59,12 @@ public override void CollectObservations(VectorSensor sensor)
Debug.Log(this.transform.parent.gameObject.name +
", " + this.name + " CollectObservations: " + carCatchingEnvController.ResetTimer);
Vector2[] obs = carCatchingEnvController.GetAgentPosObs(this);
// foreach (var myobs in obs)
// {
// Debug.Log(this.transform.parent.gameObject.name +
// ", " + this.name + " Observations: " + myobs);
// sensor.AddObservation(myobs);
// }
foreach (var myobs in obs)
{
Debug.Log(this.transform.parent.gameObject.name +
", " + this.name + " Observations: " + myobs);
sensor.AddObservation(myobs);
}
// sensor.AddOneHotObservation(2, 8);
}

Expand Down Expand Up @@ -209,8 +210,10 @@ public override void Heuristic(in ActionBuffers actionsOut)
// discreteActionsOut[0] = 2;
// }
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = 0f;
continuousActionsOut[1] = 0f;
// continuousActionsOut[0] = 0f;
// continuousActionsOut[1] = 0f;
continuousActionsOut[0] = Random.Range(-1f,1f);
continuousActionsOut[1] = Random.Range(-1f, 1f);
}

public void FixedUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CarInfo
[HideInInspector] public Vector3 StartingScale;
[HideInInspector] public DecisionRequester DecisionRequester;
[HideInInspector] public NavMeshAgent NavMeshAgent;
[HideInInspector] public LineRenderer LineRenderer;
}

/// <summary>
Expand Down Expand Up @@ -79,6 +80,7 @@ void Start()
item.StartingScale = itemTrans.localScale;
item.DecisionRequester = item.Agent.GetComponent<DecisionRequester>();
item.NavMeshAgent = item.Agent.GetComponent<NavMeshAgent>();
item.LineRenderer = item.Agent.GetComponent<LineRenderer>();
}

for (; RunningNum < AgentsList.Count && AgentsList[RunningNum].Agent.isRunning; ++RunningNum) ;
Expand Down Expand Up @@ -142,6 +144,7 @@ public void ResetScene()
var pos = UseRandomAgentPosition ? GetRandomSpawnPos(rot) : item.StartingPos;

item.Agent.transform.SetPositionAndRotation(pos, rot);
item.LineRenderer.positionCount = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ LineRenderer:
m_RotationOrder: 4
colorGradient:
serializedVersion: 2
key0: {r: 0, g: 0, b: 0, a: 1}
key1: {r: 0, g: 0, b: 0, a: 1}
key2: {r: 1, g: 0.10272626, b: 0, a: 0}
key0: {r: 1, g: 1, b: 1, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 1542
ctime2: 65535
ctime3: 0
ctime4: 0
ctime5: 0
Expand Down Expand Up @@ -263,4 +263,4 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
minDistance: 0.1
width: 2
width: 5
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LineRender : MonoBehaviour
private LineRenderer line;
private Vector3 previousPosition;
[SerializeField] private float minDistance = 0.1f;
[SerializeField, Range(0f, 20f)] private float width = 2f;
[SerializeField, Range(0f, 20f)] private float width = 5f;

private void Start()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 1, a: 1}
- _Color: {r: 0.12941177, g: 0.5882353, b: 0.9529412, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
Expand Down
Loading

0 comments on commit c01b72a

Please sign in to comment.