浏览代码

static opponent game mode

/develop/dodgeball-tests
HH 4 年前
当前提交
4eb78b8c
共有 9 个文件被更改,包括 195 次插入234 次删除
  1. 13
      Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallAgentInput.cs
  2. 28
      Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallInputActions.cs
  3. 10
      Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallInputActions.inputactions
  4. 136
      Project/Assets/ML-Agents/Examples/Dodgeball/Prefabs/DodgeballAgent.prefab
  5. 131
      Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity
  6. 23
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/AgentCubeMovement.cs
  7. 7
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs
  8. 56
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs
  9. 25
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/ThrowBall.cs

13
Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallAgentInput.cs


public Vector2 moveInput;
public bool throwInput;
public float throwInput;
public bool jumpInput;
public bool dashInput;
public Vector2 rotateInput;

return;
}
moveInput = actionMap.Walk.ReadValue<Vector2>();
throwInput = actionMap.Shoot.ReadValue<float>() > 0;
// shootPressed = actionMap.Shoot.triggered;
throwPressed = actionMap.Shoot.phase == InputActionPhase.Started;
throwInput = actionMap.Throw.ReadValue<float>();
// throwPressed = actionMap.Throw.phase == InputActionPhase.Started;
// throwPressed = actionMap.Throw.triggered;
// shootInput = gamepad.rightTrigger.isPressed;
shieldInput = actionMap.Shield.ReadValue<float>() > 0;
// rotateInput = actionMap.RotateBody.ReadValue<Vector2>();

// rotateInput = actionMap.RotateBody.ReadValue<Vector2>();
// jumpInput = actionMap.Jump.ReadValue<float>() > 0;
// jumpInput = actionMap.Jump.triggered;
// if (actionMap.Throw.phase == InputActionPhase.Started)
if (actionMap.Throw.triggered)
{
throwPressed = true;
}
if (actionMap.Dash.triggered)
{
dashInput = true;

28
Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallInputActions.cs


""interactions"": """"
},
{
""name"": ""Shoot"",
""name"": ""Throw"",
""type"": ""Button"",
""id"": ""cbcb2a57-a474-46a7-b133-cf144f6de321"",
""expectedControlType"": ""Button"",

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Shoot"",
""action"": ""Throw"",
""isComposite"": false,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Shoot"",
""action"": ""Throw"",
""isComposite"": false,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Shoot"",
""action"": ""Throw"",
""isComposite"": false,
""isPartOfComposite"": false
},

m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Walk = m_Player.FindAction("Walk", throwIfNotFound: true);
m_Player_Jump = m_Player.FindAction("Jump", throwIfNotFound: true);
m_Player_Shoot = m_Player.FindAction("Shoot", throwIfNotFound: true);
m_Player_Throw = m_Player.FindAction("Throw", throwIfNotFound: true);
m_Player_Shield = m_Player.FindAction("Shield", throwIfNotFound: true);
m_Player_Dash = m_Player.FindAction("Dash", throwIfNotFound: true);
m_Player_RotateOld = m_Player.FindAction("RotateOld", throwIfNotFound: true);

private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Walk;
private readonly InputAction m_Player_Jump;
private readonly InputAction m_Player_Shoot;
private readonly InputAction m_Player_Throw;
private readonly InputAction m_Player_Shield;
private readonly InputAction m_Player_Dash;
private readonly InputAction m_Player_RotateOld;

public PlayerActions(@DodgeBallInputActions wrapper) { m_Wrapper = wrapper; }
public InputAction @Walk => m_Wrapper.m_Player_Walk;
public InputAction @Jump => m_Wrapper.m_Player_Jump;
public InputAction @Shoot => m_Wrapper.m_Player_Shoot;
public InputAction @Throw => m_Wrapper.m_Player_Throw;
public InputAction @Shield => m_Wrapper.m_Player_Shield;
public InputAction @Dash => m_Wrapper.m_Player_Dash;
public InputAction @RotateOld => m_Wrapper.m_Player_RotateOld;

@Jump.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
@Shoot.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
@Shoot.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
@Shoot.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
@Throw.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnThrow;
@Throw.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnThrow;
@Throw.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnThrow;
@Shield.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShield;
@Shield.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShield;
@Shield.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShield;

@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
@Shoot.started += instance.OnShoot;
@Shoot.performed += instance.OnShoot;
@Shoot.canceled += instance.OnShoot;
@Throw.started += instance.OnThrow;
@Throw.performed += instance.OnThrow;
@Throw.canceled += instance.OnThrow;
@Shield.started += instance.OnShield;
@Shield.performed += instance.OnShield;
@Shield.canceled += instance.OnShield;

{
void OnWalk(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnShoot(InputAction.CallbackContext context);
void OnThrow(InputAction.CallbackContext context);
void OnShield(InputAction.CallbackContext context);
void OnDash(InputAction.CallbackContext context);
void OnRotateOld(InputAction.CallbackContext context);

10
Project/Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallInputActions.inputactions


{
"name": "FPSPlayerInputActions",
"name": "DodgeBallInputActions",
"maps": [
{
"name": "Player",

"interactions": ""
},
{
"name": "Shoot",
"name": "Throw",
"type": "Button",
"id": "cbcb2a57-a474-46a7-b133-cf144f6de321",
"expectedControlType": "Button",

"interactions": "",
"processors": "",
"groups": "",
"action": "Shoot",
"action": "Throw",
"isComposite": false,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "",
"action": "Shoot",
"action": "Throw",
"isComposite": false,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "",
"action": "Shoot",
"action": "Throw",
"isComposite": false,
"isPartOfComposite": false
},

136
Project/Assets/ML-Agents/Examples/Dodgeball/Prefabs/DodgeballAgent.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &474368874
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 474368875}
m_Layer: 11
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &474368875
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 474368874}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 6960991000376283093}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &861736839
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 6960991000376283095}
- component: {fileID: 6960991000376283092}
- component: {fileID: 6960991000376283089}
- component: {fileID: 5841309379668457540}
- component: {fileID: 8600068265116176913}
- component: {fileID: 6960991000376283101}
- component: {fileID: 6960991000376283099}
- component: {fileID: 6960991000376283103}
- component: {fileID: 886896010}

- {fileID: 8362555902365119306}
- {fileID: 8366924173547402155}
- {fileID: 8366924174162893208}
- {fileID: 474368875}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}

VectorObservationSize: 2
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
m_NumContinuousActions: 5
VectorActionSize:
VectorActionSize: 05000000
VectorActionSpaceType: 0
VectorActionSpaceType: 1
m_BehaviorType: 1
m_BehaviorType: 0
m_BehaviorName: DodgeBall
TeamId: 0
m_UseChildSensors: 1

MaxStep: 0
teamID: 0
ThrowController: {fileID: 8366924173413481317}
AgentHealth: {fileID: 8600068265116176913}
AgentShield: {fileID: 5841309379668457540}
input: {fileID: 0}
AgentHealth: {fileID: 0}
AgentShield: {fileID: 0}
input: {fileID: 886896010}
currentNumberOfBalls: 0
currentlyHeldBalls: []
UseVectorObs: 1

m_Script: {fileID: 11500000, guid: 0b86732e5cf714ed6ba8b18dd80f458c, type: 3}
m_Name:
m_EditorClassIdentifier:
allowHumanInput: 1
allowHumanInput: 0
maxAngularVel: 50
runningForceMode: 2
agentRunSpeed: 10

isGrounded: 1
ungroundedTime: 0
groundedTime: 3.119217
--- !u!114 &5841309379668457540
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6960991000376283098}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 77c3fcb98988a4fd1a6a820b2c5331cb, type: 3}
m_Name:
m_EditorClassIdentifier:
shieldKey: 105
shieldGO: {fileID: 8708871947828733902}
ShieldIsActive: 0
CurrentPercentage: 100
DepletionRate: 5
RegenRate: 0.25
UISlider: {fileID: 0}
--- !u!114 &8600068265116176913
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6960991000376283098}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9227871cd6ab8429d90afa4a5160924e, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentPercentage: 89
UISlider: {fileID: 0}
bodyMesh: {fileID: 6960991001359725249}
damageColor: {r: 1, g: 0, b: 0, a: 0}
startingColor: {r: 0.1294118, g: 0.5882353, b: 0.9529412, a: 1}
damageFlashDuration: 0.02
ShieldController: {fileID: 5841309379668457540}
CubeBody: {fileID: 6960991001359725255}
DeathCube: {fileID: 8366924173617838012}
ExplosionParticles: {fileID: 1722726733478836, guid: c1c88308ebb5d2541a282905b854ee4c,
type: 3}
impulseSource: {fileID: 0}
ResetSceneAfterDeath: 1
Dead: 0
UseGlobalDamageSettings: 0
DamagePerHit: 1
--- !u!114 &6960991000376283101
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6960991000376283098}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ceeb907ca54e84d77b6d31c0a264e386, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 6960991000376283093}
canCurrentlySeeTarget: 0
RunTowardsTarget: 1
OnlyWalkIfCanSeeTarget: 1
MaxRotationRate: 25
RandomRotationJitter: 1.5
TargetTag: agent
RotateTowardsTarget: 1
OnlyShootIfCanSeeTarget: 1
--- !u!114 &6960991000376283099
MonoBehaviour:
m_ObjectHideFlags: 0

m_EditorClassIdentifier:
DisableInput: 0
moveInput: {x: 0, y: 0}
shootInput: 0
throwInput: 0
shootPressed: 0
throwPressed: 0
--- !u!1 &6960991000723819014
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9116796388679672958}
m_LocalRotation: {x: 0.023514433, y: -0.0000000052765476, z: 1.2410933e-10, w: 0.9997235}
m_LocalRotation: {x: 0.023514416, y: 3.1894046e-10, z: -7.5017536e-12, w: 0.9997235}
m_LocalPosition: {x: 0, y: 1.9999999, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

objectReference: {fileID: 2100000, guid: cb2aa8892bed247b58476624d7896b0f, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1b24fe96fd75b4646a6e7bf65b6a4943, type: 3}
--- !u!1 &7210080383517242672 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7210080383517242672 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}

131
Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity


shootKey: 106
autoShootEnabled: 0
shootingRate: 0.02
coolDownTimer: 0
coolDownWait: 0
projectilePrefab: {fileID: 3911029810215854908, guid: 4c3111f00dcbe425186833fe890fcac7,
type: 3}

propertyPath: UISlider
value:
objectReference: {fileID: 920197661}
- target: {fileID: 5841309379668457540, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BehaviorName

propertyPath: TeamId
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BehaviorType
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283092, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: cam

- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalPosition.x
value: 21.6
value: 15.16
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}

- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalPosition.z
value: -26.1
value: -13.44
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}

propertyPath: DoNotPerformActions
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283102, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283102, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: teamID
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6960991001359725249, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_Materials.Array.data[0]

propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8366924174162893207, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8367363780074625334, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_IsActive

propertyPath: UISlider
value:
objectReference: {fileID: 459618382}
- target: {fileID: 8600068265116176913, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9116796388679672956, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalRotation.x

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 884017384}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &886896010 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 886896010, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
m_PrefabInstance: {fileID: 8366924174629554752}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3d133f7ef3e34484b28a9e1605e48ab, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &901937412
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 374912651}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1687031028}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b99d81144ad24d58ae2783dbdfa24a8, type: 3}
m_Name:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1687031028}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 82a1fcfa767384bd7ac98caafc5489aa, type: 3}
m_Name:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1793097525}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1793398084 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6960991000376283098, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
m_PrefabInstance: {fileID: 8366924174629554752}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1793398085
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1793398084}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dd8012d5925524537b27131fef517017, type: 3}
m_Name:
m_EditorClassIdentifier:
ObservableSize: 0
MaxNumObservables: 0
--- !u!1 &1796672013
GameObject:
m_ObjectHideFlags: 0

type: 3}
m_PrefabInstance: {fileID: 8366924174629554752}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_GameObject: {fileID: 1793398084}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b99d81144ad24d58ae2783dbdfa24a8, type: 3}

propertyPath: Cam
value:
objectReference: {fileID: 8697938321410268831}
- target: {fileID: 5841309379668457540, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: UISlider
value:
objectReference: {fileID: 920197661}
propertyPath: m_BrainParameters.VectorActionSize.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BehaviorType
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BrainParameters.m_ActionSpec.m_NumContinuousActions
value: 5
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BrainParameters.VectorActionSize.Array.data[0]
value: 5
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283046, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_BrainParameters.VectorActionSpaceType
value: 1
propertyPath: m_BrainParameters.VectorObservationSize
value: 3
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283092, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}

- target: {fileID: 6960991000376283092, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: allowHumanInput
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalPosition.x

- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalPosition.z
value: -0.9
value: -5.14
objectReference: {fileID: 0}
- target: {fileID: 6960991000376283093, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}

objectReference: {fileID: 0}
- target: {fileID: 6960991000376283102, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: input
value:
objectReference: {fileID: 886896010}
- target: {fileID: 6960991000376283102, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_Enabled
value: 1
propertyPath: MaxStep
value: 3000
- target: {fileID: 8600068265116176913, guid: 1c6bcdaf8b76745d8918fc47c464885e,
- target: {fileID: 8366924173413481317, guid: 1c6bcdaf8b76745d8918fc47c464885e,
propertyPath: UISlider
value:
objectReference: {fileID: 459618382}
propertyPath: shootingRate
value: 0.25
objectReference: {fileID: 0}
- target: {fileID: 9116796388679672956, guid: 1c6bcdaf8b76745d8918fc47c464885e,
type: 3}
propertyPath: m_LocalRotation.x

propertyPath: m_BoundingVolume
value:
objectReference: {fileID: 327417535}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 8366924173413481316, guid: 1c6bcdaf8b76745d8918fc47c464885e, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 1c6bcdaf8b76745d8918fc47c464885e, type: 3}
--- !u!33 &8600386897362527026
MeshFilter:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8697938321410268827}
m_LocalRotation: {x: -7.5017536e-12, y: 0.9997235, z: -0.023514416, w: -3.1894046e-10}
m_LocalPosition: {x: 20.4, y: 3.1269999, z: 4.1}
m_LocalPosition: {x: 20.4, y: 3.1269999, z: -0.13999987}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

23
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/AgentCubeMovement.cs


{
if (!allowHumanInput)
{
//FORWARD MOVEMENT
inputV = Input.GetAxisRaw("Vertical");
inputH = Input.GetAxisRaw("Horizontal");
spinAttack = Input.GetKey(KeyCode.H);
dashPressed = Input.GetKeyDown(KeyCode.K);
jump = Input.GetKeyDown(KeyCode.Space);
//FORWARD MOVEMENT
inputV = Input.GetAxisRaw("Vertical");
inputH = Input.GetAxisRaw("Horizontal");
spinAttack = Input.GetKey(KeyCode.H);
dashPressed = Input.GetKeyDown(KeyCode.K);
jump = Input.GetKeyDown(KeyCode.Space);
var camForward = cam.transform.forward;
camForward.y = 0;
var camRight = cam.transform.right;

strafeCoolDownTimer += Time.fixedDeltaTime;
dashCoolDownTimer += Time.fixedDeltaTime;
if (groundCheck && !groundCheck.isGrounded)
{
AddFallingForce(rb);
// print("AddFallingForce");
}
if (!allowHumanInput)
{
return;

}
if (groundCheck && !groundCheck.isGrounded)
{
AddFallingForce(rb);
// print("AddFallingForce");
}
if (applyStandingForce)
{

7
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs


if (UseVectorObs)
{
// sensor.AddObservation((float)StepCount / (float)MaxStep); //Helps with credit assign?
sensor.AddObservation(ThrowController.coolDownWait); //Held DBs Normalized
sensor.AddObservation((float)currentNumberOfBalls/4); //Held DBs Normalized
sensor.AddObservation((float)HitPointsRemaining/(float)NumberOfTimesPlayerCanBeHit); //Remaining Hit Points Normalized
// // var localVelocity = transform.InverseTransformDirection(m_AgentRb.velocity);

public void ThrowTheBall()
{
if (currentNumberOfBalls > 0)
if (currentNumberOfBalls > 0 && !ThrowController.coolDownWait)
{
var db = ActiveBallsQueue.Peek();
ThrowController.Throw(db, m_BehaviorParameters.TeamId);

contActionsOut[0] = input.moveInput.y;
contActionsOut[1] = input.moveInput.x;
contActionsOut[2] = input.rotateInput.x; //rotate
contActionsOut[3] = input.throwPressed ? 1 : 0; //shoot
// contActionsOut[3] = input.throwPressed ? 1 : 0; //shoot
contActionsOut[3] = input.CheckIfInputSinceLastFrame(ref input.throwPressed) ? 1 : 0; //dash
// contActionsOut[3] = input.throwInput; //shoot
contActionsOut[4] = input.CheckIfInputSinceLastFrame(ref input.dashInput) ? 1 : 0; //dash
}
}

56
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs


print($"{agent.name} Lost.{agent.name} was weak:");
//ASSIGN REWARDS
// EndEpisode();
agent.AddReward(-1f); //you lost penalty
// agent.AddReward(-1f); //you lost penalty
HitByTeamList[0].Agent.AddReward(1);
if (info.TeamID == 0)
{

{
info.HitPointsRemaining--;
//ASSIGN REWARDS
agent.AddReward(-.1f); //small hit penalty
// agent.AddReward(-.1f); //small hit penalty
HitByTeamList[0].Agent.AddReward(.1f);
}
// ResetScene();

// public void PlayerWasHit(DodgeBallAgent agent)
// {
// //SET AGENT/TEAM REWARDS HERE
// AgentInfo info = PlayersDict[agent];
// int hitTeamID = info.TeamID;
// // var HitTeamList = hitTeamID == 0 ? Team0Players : Team1Players;
// var HitByTeamList = hitTeamID == 1 ? Team0Players : Team1Players;
// // int hitByTeamID = hitTeamID == 0? 1: 0; //assumes only 2 teams
//
// if (info.HitPointsRemaining == 1)
// {
// //RESET ENV
// print($"{agent.name} Lost.{agent.name} was weak:");
// //ASSIGN REWARDS
// // EndEpisode();
// agent.AddReward(-1f); //you lost penalty
// HitByTeamList[0].Agent.AddReward(1);
// if (info.TeamID == 0)
// {
// print($"Team 1 Won");
// }
// else if (info.TeamID == 1)
// {
// print($"Team 0 Won");
// }
// ResetScene();
// }
// else
// {
// info.HitPointsRemaining--;
// //ASSIGN REWARDS
// agent.AddReward(-.1f); //small hit penalty
// HitByTeamList[0].Agent.AddReward(.1f);
// }
// // ResetScene();
//
// }
void ResetScene()

//End Episode
foreach (var item in Team0Players)
{
item.Agent.EndEpisode();
item.HitPointsRemaining = PlayerMaxHitPoints;
if (item.Agent.enabled)
{
item.Agent.EndEpisode();
item.HitPointsRemaining = PlayerMaxHitPoints;
}
item.Agent.EndEpisode();
item.HitPointsRemaining = PlayerMaxHitPoints;
if (item.Agent.enabled)
{
item.Agent.EndEpisode();
item.HitPointsRemaining = PlayerMaxHitPoints;
}
}
// //Reset Agents

25
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/ThrowBall.cs


//SHOOTING RATE
[Header("SHOOTING RATE")]
public float shootingRate = .02f; //can shoot every shootingRate seconds. ex: .5 can shoot every .5 seconds
// private float shootTimer;
public float coolDownTimer;
public bool coolDownWait;
//PROJECTILES

// }
// }
// void FixedUpdate()
// {
// coolDownWait = shootTimer > shootingRate ? false : true;
// shootTimer += Time.fixedDeltaTime;
// if (autoShootEnabled)
// {
// Shoot();
// }
// }
void FixedUpdate()
{
coolDownWait = coolDownTimer > shootingRate ? false : true;
coolDownTimer += Time.fixedDeltaTime;
// if (autoShootEnabled)
// {
// Shoot();
// }
}
// public void ShootQuantity(int num)
// {

//ignoreTeam. 0 ignores team 0, 1 ignores team 1, -1 ignores no teams
public void Throw(DodgeBall db, int ignoreTeam = -1)
{
if (coolDownWait || !gameObject.activeSelf)
{
return;
}
coolDownTimer = 0; //reset timer
db.BallIsInPlay(true, ignoreTeam);
FireProjectile(db.rb);
}

正在加载...
取消
保存