Ervin Teng
4 年前
当前提交
9d20139b
共有 9 个文件被更改,包括 2166 次插入 和 11 次删除
-
22Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
-
1001Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab
-
7Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity
-
7Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity.meta
-
50Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallAreaScoring.cs
-
11Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallAreaScoring.cs.meta
-
67Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpCollabAgent.cs
-
11Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpCollabAgent.cs.meta
1001
Project/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpCollabArea.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: ff1a5743be49d43f08378dcd76451821 |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/WallJump/Scenes/WallJumpCollab.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 136090e065a8f48bfb97ea3083893d8a |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class WallAreaScoring : MonoBehaviour |
|||
{ |
|||
public GameObject[] agents; |
|||
WallJumpSettings m_WallJumpSettings; |
|||
Renderer m_GroundRenderer; |
|||
Material m_GroundMaterial; |
|||
|
|||
protected IEnumerator GoalScoredSwapGroundMaterial(Material mat, float time) |
|||
{ |
|||
m_GroundRenderer.material = mat; |
|||
yield return new WaitForSeconds(time); //wait for 2 sec
|
|||
m_GroundRenderer.material = m_GroundMaterial; |
|||
} |
|||
|
|||
public void Start() |
|||
{ |
|||
m_WallJumpSettings = FindObjectOfType<WallJumpSettings>(); |
|||
m_GroundRenderer = GetComponent<Renderer>(); |
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
} |
|||
|
|||
public void WinCondition() |
|||
{ |
|||
foreach (var agent in agents) |
|||
{ |
|||
WallJumpCollabAgent agentScript = agent.GetComponent<WallJumpCollabAgent>(); |
|||
agentScript.SetReward(1f); |
|||
agentScript.EndEpisode(); |
|||
} |
|||
StartCoroutine( |
|||
GoalScoredSwapGroundMaterial(m_WallJumpSettings.goalScoredMaterial, 1f)); |
|||
} |
|||
|
|||
public void LoseCondition() |
|||
{ |
|||
foreach (var agent in agents) |
|||
{ |
|||
WallJumpCollabAgent agentScript = agent.GetComponent<WallJumpCollabAgent>(); |
|||
agentScript.SetReward(-1f); |
|||
agentScript.EndEpisode(); |
|||
|
|||
} |
|||
StartCoroutine( |
|||
GoalScoredSwapGroundMaterial(m_WallJumpSettings.failMaterial, .2f)); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ad7213222795741f5b6ca2b332f16da9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//Put this script on your blue cube.
|
|||
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using Unity.MLAgents; |
|||
using Unity.Barracuda; |
|||
using Unity.MLAgents.Actuators; |
|||
using Unity.MLAgents.Sensors; |
|||
using Unity.MLAgentsExamples; |
|||
|
|||
public class WallJumpCollabAgent : WallJumpAgent |
|||
{ |
|||
Vector3 m_InitialPosition; |
|||
|
|||
WallAreaScoring m_Scoring; |
|||
public override void Initialize() |
|||
{ |
|||
m_WallJumpSettings = FindObjectOfType<WallJumpSettings>(); |
|||
m_Scoring = ground.GetComponent<WallAreaScoring>(); |
|||
m_Configuration = 5; |
|||
|
|||
m_AgentRb = GetComponent<Rigidbody>(); |
|||
// m_ShortBlockRb = shortBlock.GetComponent<Rigidbody>();
|
|||
m_SpawnAreaBounds = spawnArea.GetComponent<Collider>().bounds; |
|||
m_GroundRenderer = ground.GetComponent<Renderer>(); |
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
m_InitialPosition = transform.localPosition; |
|||
spawnArea.SetActive(false); |
|||
|
|||
m_ResetParams = Academy.Instance.EnvironmentParameters; |
|||
} |
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
transform.localPosition = m_InitialPosition; |
|||
m_Configuration = 5; |
|||
m_AgentRb.velocity = default(Vector3); |
|||
} |
|||
|
|||
public override void OnActionReceived(ActionBuffers actionBuffers) |
|||
{ |
|||
MoveAgent(actionBuffers.DiscreteActions); |
|||
if (!Physics.Raycast(m_AgentRb.position, Vector3.down, 20)) |
|||
{ |
|||
m_Scoring.LoseCondition(); |
|||
} |
|||
} |
|||
|
|||
protected override void ConfigureAgent(int config) |
|||
{ |
|||
var localScale = wall.transform.localScale; |
|||
var height = m_ResetParams.GetWithDefault("big_wall_height", 10); |
|||
localScale = new Vector3( |
|||
localScale.x, |
|||
height, |
|||
localScale.z); |
|||
wall.transform.localScale = localScale; |
|||
} |
|||
|
|||
// Detect when the agent hits the goal
|
|||
protected override void OnTriggerStay(Collider col) |
|||
{ |
|||
if (col.gameObject.CompareTag("goal") && DoGroundCheck(true)) |
|||
{ |
|||
m_Scoring.WinCondition(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2cdbc0d9a64fe4b12a3ed4b81a151117 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue