浏览代码
Add TargetController/OrientationCubeController Components & Bugfix (#4157)
Add TargetController/OrientationCubeController Components & Bugfix (#4157)
* added Target and OCube controllers. updated crawler envs * update walker prefab * add refs to prefab * Update Crawler.prefab * update platform, ragdoll, ocube prefabs * reformat file * reformat files * fix behavior name * add final retrained crawler and walker nn files * collect hip ocube rot in world space * update crawler observations and update prefabs * change to 20M steps * update crwl prefab to 142 observ * update obsvs to 241. add expvel reward * change walkspeed to 3 * add new crawler and walker nn files * adjust rewards * enable other pairs * add RewardManager * cleanup about to do final training * cleanup add nn files for increased facing rew reduced height rew * try no facing rew * add vel only policy, try dy target * inc torq on cube * added dynamic cube nn. gonna try 40M steps * add 40M step test, more cleanup * ch.../MLA-1734-demo-provider
GitHub
4 年前
当前提交
8b913a96
共有 33 个文件被更改,包括 3190 次插入 和 3645 次删除
-
65Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Crawler.prefab
-
385Project/Assets/ML-Agents/Examples/Crawler/Prefabs/DynamicPlatform.prefab
-
286Project/Assets/ML-Agents/Examples/Crawler/Prefabs/FixedPlatform.prefab
-
45Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicTarget.unity
-
381Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticTarget.unity
-
111Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
-
1001Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn
-
2Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn
-
2Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn.meta
-
5Project/Assets/ML-Agents/Examples/SharedAssets/Materials/Outline.mat
-
5Project/Assets/ML-Agents/Examples/SharedAssets/Materials/UIDefault.mat
-
15Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/OrientationCube.prefab
-
7Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/JointDriveController.cs
-
310Project/Assets/ML-Agents/Examples/Walker/Prefabs/DynamicPlatformWalker.prefab
-
153Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerRagdoll.prefab
-
277Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerWithTargetPair.prefab
-
76Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerDynamic.unity
-
60Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity
-
137Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerDynamic.nn
-
2Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerDynamic.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerStatic.nn
-
2Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerStatic.nn.meta
-
2config/ppo/WalkerDynamic.yaml
-
159Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/DynamicTarget.prefab
-
7Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/DynamicTarget.prefab.meta
-
149Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/StaticTarget.prefab
-
7Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/StaticTarget.prefab.meta
-
24Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/OrientationCubeController.cs
-
11Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/OrientationCubeController.cs.meta
-
135Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/TargetController.cs
-
11Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/TargetController.cs.meta
1001
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
1001
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerDynamic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/WalkerStatic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1 &3840539935788495952 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 3839136118347789758} |
|||
- component: {fileID: 3836793085241645916} |
|||
- component: {fileID: 3868551391811062596} |
|||
- component: {fileID: 3826955612593018128} |
|||
- component: {fileID: 3858402326794362026} |
|||
- component: {fileID: 3631016866778687563} |
|||
m_Layer: 0 |
|||
m_Name: DynamicTarget |
|||
m_TagString: target |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &3839136118347789758 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: 1, y: 1, z: 1} |
|||
m_LocalScale: {x: 1.2356956, y: 1.2356961, z: 1.2356961} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &3836793085241645916 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!65 &3868551391811062596 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!23 &3826955612593018128 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 0 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 1 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: c67450f290f3e4897bc40276a619e78d, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_PreserveUVs: 1 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
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 |
|||
--- !u!54 &3858402326794362026 |
|||
Rigidbody: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
serializedVersion: 2 |
|||
m_Mass: 1 |
|||
m_Drag: 0 |
|||
m_AngularDrag: 0.05 |
|||
m_UseGravity: 1 |
|||
m_IsKinematic: 0 |
|||
m_Interpolate: 0 |
|||
m_Constraints: 0 |
|||
m_CollisionDetection: 3 |
|||
--- !u!114 &3631016866778687563 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 3c8f113a8b8d94967b1b1782c549be81, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
tagToDetect: agent |
|||
spawnRadius: 40 |
|||
respawnIfTouched: 1 |
|||
respawnIfFallsOffPlatform: 1 |
|||
fallDistance: 5 |
|||
triggerIsTouching: 0 |
|||
onTriggerEnterEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onTriggerStayEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onTriggerExitEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
colliderIsTouching: 0 |
|||
onCollisionEnterEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: |
|||
- m_Target: {fileID: 0} |
|||
m_MethodName: TouchedTarget |
|||
m_Mode: 1 |
|||
m_Arguments: |
|||
m_ObjectArgument: {fileID: 0} |
|||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine |
|||
m_IntArgument: 0 |
|||
m_FloatArgument: 0 |
|||
m_StringArgument: |
|||
m_BoolArgument: 0 |
|||
m_CallState: 2 |
|||
onCollisionStayEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onCollisionExitEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|
|||
fileFormatVersion: 2 |
|||
guid: 46734abd0de454192b407379c6a4ab8d |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1 &3840539935788495952 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 3839136118347789758} |
|||
- component: {fileID: 3836793085241645916} |
|||
- component: {fileID: 3868551391811062596} |
|||
- component: {fileID: 3826955612593018128} |
|||
- component: {fileID: 3858402326794362026} |
|||
- component: {fileID: 3631016866778687563} |
|||
m_Layer: 0 |
|||
m_Name: StaticTarget |
|||
m_TagString: target |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &3839136118347789758 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
|||
m_LocalPosition: {x: 6.2, y: 1.15, z: 3.824} |
|||
m_LocalScale: {x: 1.2356956, y: 1.2356961, z: 1.2356961} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &3836793085241645916 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!65 &3868551391811062596 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!23 &3826955612593018128 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 0 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 1 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: c67450f290f3e4897bc40276a619e78d, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_PreserveUVs: 1 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
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 |
|||
--- !u!54 &3858402326794362026 |
|||
Rigidbody: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
serializedVersion: 2 |
|||
m_Mass: 5 |
|||
m_Drag: 0 |
|||
m_AngularDrag: 0.05 |
|||
m_UseGravity: 1 |
|||
m_IsKinematic: 0 |
|||
m_Interpolate: 0 |
|||
m_Constraints: 0 |
|||
m_CollisionDetection: 0 |
|||
--- !u!114 &3631016866778687563 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 3840539935788495952} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 3c8f113a8b8d94967b1b1782c549be81, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
tagToDetect: agent |
|||
moveTargetToRandomPosIfTouched: 0 |
|||
targetSpawnRadius: 0 |
|||
onTrtesiggerEnterEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
triggerIsTouching: 0 |
|||
onTriggerEnterEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onTriggerStayEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onTriggerExitEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
colliderIsTouching: 0 |
|||
onCollisionEnterEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onCollisionStayEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|||
onCollisionExitEvent: |
|||
m_PersistentCalls: |
|||
m_Calls: [] |
|
|||
fileFormatVersion: 2 |
|||
guid: 2173d15c0b5fc49e5870c9d1c7f7ee8e |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgentsExamples |
|||
{ |
|||
/// <summary>
|
|||
/// Utility class to allow a stable observation platform.
|
|||
/// </summary>
|
|||
public class OrientationCubeController : MonoBehaviour |
|||
{ |
|||
//Update position and Rotation
|
|||
public void UpdateOrientation(Transform rootBP, Transform target) |
|||
{ |
|||
var dirVector = target.position - transform.position; |
|||
dirVector.y = 0; //flatten dir on the y. this will only work on level, uneven surfaces
|
|||
var lookRot = |
|||
dirVector == Vector3.zero |
|||
? Quaternion.identity |
|||
: Quaternion.LookRotation(dirVector); //get our look rot to the target
|
|||
|
|||
//UPDATE ORIENTATION CUBE POS & ROT
|
|||
transform.SetPositionAndRotation(rootBP.position, lookRot); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 771e78c5e980e440e8cd19716b55075f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using Random = UnityEngine.Random; |
|||
using Unity.MLAgents; |
|||
using UnityEngine.Events; |
|||
|
|||
namespace Unity.MLAgentsExamples |
|||
{ |
|||
/// <summary>
|
|||
/// Utility class to allow target placement and collision detection with an agent
|
|||
/// Add this script to the target you want the agent to touch.
|
|||
/// Callbacks will be triggered any time the target is touched with a collider tagged as 'tagToDetect'
|
|||
/// </summary>
|
|||
public class TargetController : MonoBehaviour |
|||
{ |
|||
|
|||
[Header("Collider Tag To Detect")] |
|||
public string tagToDetect = "agent"; //collider tag to detect
|
|||
|
|||
[Header("Target Placement")] |
|||
public float spawnRadius; //The radius in which a target can be randomly spawned.
|
|||
public bool respawnIfTouched; //Should the target respawn to a different position when touched
|
|||
|
|||
[Header("Target Fell Protection")] |
|||
public bool respawnIfFallsOffPlatform = true; //If the target falls off the platform, reset the position.
|
|||
public float fallDistance = 5; //distance below the starting height that will trigger a respawn
|
|||
|
|||
|
|||
private Vector3 m_startingPos; //the starting position of the target
|
|||
private Agent m_agentTouching; //the agent currently touching the target
|
|||
|
|||
[System.Serializable] |
|||
public class TriggerEvent : UnityEvent<Collider> |
|||
{ |
|||
} |
|||
|
|||
[Header("Trigger Callbacks")] |
|||
public TriggerEvent onTriggerEnterEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerStayEvent = new TriggerEvent(); |
|||
public TriggerEvent onTriggerExitEvent = new TriggerEvent(); |
|||
|
|||
[System.Serializable] |
|||
public class CollisionEvent : UnityEvent<Collision> |
|||
{ |
|||
} |
|||
|
|||
[Header("Collision Callbacks")] |
|||
public CollisionEvent onCollisionEnterEvent = new CollisionEvent(); |
|||
public CollisionEvent onCollisionStayEvent = new CollisionEvent(); |
|||
public CollisionEvent onCollisionExitEvent = new CollisionEvent(); |
|||
|
|||
// Start is called before the first frame update
|
|||
void OnEnable() |
|||
{ |
|||
m_startingPos = transform.position; |
|||
if (respawnIfTouched) |
|||
{ |
|||
MoveTargetToRandomPosition(); |
|||
} |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (respawnIfFallsOffPlatform) |
|||
{ |
|||
if (transform.position.y < m_startingPos.y - fallDistance) |
|||
{ |
|||
Debug.Log($"{transform.name} Fell Off Platform"); |
|||
MoveTargetToRandomPosition(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Moves target to a random position within specified radius.
|
|||
/// </summary>
|
|||
public void MoveTargetToRandomPosition() |
|||
{ |
|||
var newTargetPos = m_startingPos + (Random.insideUnitSphere * spawnRadius); |
|||
newTargetPos.y = m_startingPos.y; |
|||
transform.position = newTargetPos; |
|||
} |
|||
|
|||
private void OnCollisionEnter(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionEnterEvent.Invoke(col); |
|||
if (respawnIfTouched) |
|||
{ |
|||
MoveTargetToRandomPosition(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void OnCollisionStay(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionStayEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnCollisionExit(Collision col) |
|||
{ |
|||
if (col.transform.CompareTag(tagToDetect)) |
|||
{ |
|||
onCollisionExitEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerEnter(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerEnterEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerStay(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerStayEvent.Invoke(col); |
|||
} |
|||
} |
|||
|
|||
private void OnTriggerExit(Collider col) |
|||
{ |
|||
if (col.CompareTag(tagToDetect)) |
|||
{ |
|||
onTriggerExitEvent.Invoke(col); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3c8f113a8b8d94967b1b1782c549be81 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue