浏览代码

updated input and agent script

/hh-develop-fps_game_project
HH 4 年前
当前提交
8b49dc9d
共有 5 个文件被更改,包括 297 次插入125 次删除
  1. 240
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  2. 76
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentCubeMovement.cs
  3. 74
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/FPSAgent.cs
  4. 4
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GunController.cs
  5. 28
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/MultiGunAlternating.cs

240
Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity


m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9482479}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -20, y: 1.0000002, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -6.5114603, y: 0, z: 20.442457}
m_Father: {fileID: 0}
m_RootOrder: 6
m_Father: {fileID: 530398460}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &25528574
GameObject:

objectReference: {fileID: 0}
- target: {fileID: 4943719350691982, guid: 5889392e3f05b448a8a06c5def6c2dec, type: 3}
propertyPath: m_RootOrder
value: 20
value: 13
objectReference: {fileID: 0}
- target: {fileID: 4943719350691982, guid: 5889392e3f05b448a8a06c5def6c2dec, type: 3}
propertyPath: m_LocalEulerAnglesHint.x

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 311061760}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 18.74, y: -1.05, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 32.22854, y: -2.0500002, z: 20.442457}
m_Father: {fileID: 0}
m_RootOrder: 23
m_Father: {fileID: 1817059483}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &314099675
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 314099675}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -32.01, y: -0.14, z: -48.68}
m_LocalPosition: {x: -18.521458, y: -1.1400002, z: -28.237543}
m_Father: {fileID: 0}
m_RootOrder: 21
m_Father: {fileID: 1817059483}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &338705764
GameObject:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 443995276}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -15.28, y: 2.81, z: -25.16}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -1.79146, y: 1.8099997, z: -4.7175426}
m_Father: {fileID: 0}
m_RootOrder: 24
m_Father: {fileID: 1817059483}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &459618380
GameObject:

m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -20, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &530398459
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 530398460}
m_Layer: 0
m_Name: SIMPLE
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &530398460
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 530398459}
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:
- {fileID: 9482483}
- {fileID: 932717271}
m_Father: {fileID: 1055797308}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &560188123
GameObject:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 802143321}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -24.26, y: 6.31, z: -30.36}
m_LocalPosition: {x: -10.771461, y: 5.3099995, z: -9.917543}
m_Father: {fileID: 0}
m_RootOrder: 11
m_Father: {fileID: 1817059483}
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &849921573
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 873326158}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 21, y: 1, z: -13.2}
m_LocalPosition: {x: 34.48854, y: 0, z: 7.2424574}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 64029256}

- {fileID: 338705765}
- {fileID: 1609129051}
- {fileID: 1007987871}
m_Father: {fileID: 0}
m_RootOrder: 22
m_Father: {fileID: 1817059483}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &904002122
GameObject:

m_Children:
- {fileID: 58198995}
m_Father: {fileID: 0}
m_RootOrder: 15
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 932717267}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 20, y: 1.0000002, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 33.48854, y: 0, z: 20.442457}
m_Father: {fileID: 0}
m_RootOrder: 7
m_Father: {fileID: 530398460}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &943568426
GameObject:

m_Children:
- {fileID: 1828481692}
m_Father: {fileID: 0}
m_RootOrder: 18
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &975117374
GameObject:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 975117374}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -30.56, y: -1.67, z: -25.16}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -17.07146, y: -2.67, z: -4.7175426}
m_Father: {fileID: 0}
m_RootOrder: 25
m_Father: {fileID: 1817059483}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &984743962
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1028612598}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1055797307
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1055797308}
m_Layer: 0
m_Name: =====ENVS=====
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1055797308
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1055797307}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -13.48854, y: 1.0000002, z: -20.442457}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 530398460}
- {fileID: 1817059483}
m_Father: {fileID: 0}
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1103948492
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 17
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1165970996
GameObject:

m_Script: {fileID: 11500000, guid: 839028af332e14618a5c21629d48371c, type: 3}
m_Name:
m_EditorClassIdentifier:
StandbyMode: 0
AllowKeyboardInput: 1
shootKey: 106
autoShootEnabled: 1
shootingRate: 0.2

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1254413876}
m_LocalRotation: {x: -0, y: 0.0000002533197, z: -0, w: -1}
m_LocalPosition: {x: 2.89, y: 1.127, z: -15.63}
m_LocalPosition: {x: 16.37854, y: 0.12699974, z: 4.812457}
m_Father: {fileID: 0}
m_RootOrder: 4
m_Father: {fileID: 1817059483}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1301582494
GameObject:

- target: {fileID: 224194346362733190, guid: 3ce107b4a79bc4eef83afde434932a68,
type: 3}
propertyPath: m_RootOrder
value: 13
value: 6
objectReference: {fileID: 0}
- target: {fileID: 224194346362733190, guid: 3ce107b4a79bc4eef83afde434932a68,
type: 3}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 19
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1527549674
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1628638785}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -36.26, y: 6.31, z: -30.36}
m_LocalPosition: {x: -22.771458, y: 5.3099995, z: -9.917543}
m_Father: {fileID: 0}
m_RootOrder: 26
m_Father: {fileID: 1817059483}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1636260632
GameObject:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1738142527}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.47, z: -25}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 13.48854, y: -1.4700003, z: -4.557543}
m_Father: {fileID: 0}
m_RootOrder: 8
m_Father: {fileID: 1817059483}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1793097525
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1793097525}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1817059482
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1817059483}
m_Layer: 0
m_Name: ADVANCED
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1817059483
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1817059482}
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:
- {fileID: 1254413879}
- {fileID: 314099676}
- {fileID: 873326159}
- {fileID: 311061764}
- {fileID: 443995280}
- {fileID: 975117378}
- {fileID: 1628638786}
- {fileID: 1738142531}
- {fileID: 2043454555}
- {fileID: 1846705532}
- {fileID: 802143322}
m_Father: {fileID: 1055797308}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1828481691
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1846705528}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.06, y: -1.67, z: -25.16}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 12.428539, y: -2.67, z: -4.7175426}
m_Father: {fileID: 0}
m_RootOrder: 10
m_Father: {fileID: 1817059483}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1966884490
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2021010774
GameObject:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2043454551}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.14, y: -3.21, z: -20.6}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 17.62854, y: -4.21, z: -0.15754318}
m_Father: {fileID: 0}
m_RootOrder: 9
m_Father: {fileID: 1817059483}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2074207737
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1028749630731591
GameObject:

- {fileID: 8209659745319036397}
- {fileID: 1479187681323959701}
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4684408441263499
Transform:

- {fileID: 101131029}
- {fileID: 1302122855}
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}

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

strafeCoolDownDuration: 0
strafeCoolDownTimer: 0
strafeForceMode: 2
dashBoostForce: 20
dashForceMode: 1

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1479187681323959706}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 20ff6ddcc32eb44f6897ea0d9e837815, type: 3}
m_Name:

hasUpgradedFromAgentParameters: 1
MaxStep: 5000
gunController: {fileID: 0}
gunController: {fileID: 7759475058439974328}
useVectorObs: 1
--- !u!114 &1543860467109742330
MonoBehaviour:

m_Script: {fileID: 11500000, guid: 839028af332e14618a5c21629d48371c, type: 3}
m_Name:
m_EditorClassIdentifier:
StandbyMode: 1
AllowKeyboardInput: 0
shootKey: 106
autoShootEnabled: 0
shootingRate: 0.02

m_Script: {fileID: 11500000, guid: 839028af332e14618a5c21629d48371c, type: 3}
m_Name:
m_EditorClassIdentifier:
StandbyMode: 1
AllowKeyboardInput: 0
shootKey: 106
autoShootEnabled: 0
shootingRate: 0.02

propertyPath: m_Name
value: Projectile
objectReference: {fileID: 0}
- target: {fileID: 3911029810215854908, guid: 01e75f85d5a3c451b9a5bed7070be0a0,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 01e75f85d5a3c451b9a5bed7070be0a0, type: 3}
--- !u!23 &7628610254223227171

m_Script: {fileID: 11500000, guid: 0759b2416b6374748b3c4bc904d0bdb7, type: 3}
m_Name:
m_EditorClassIdentifier:
AllowKeyboardInput: 0
shootKey: 106
autoShootEnabled: 0
gunList:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!33 &8209659745340690325
MeshFilter:
m_ObjectHideFlags: 0

76
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentCubeMovement.cs


[Header("STRAFE")]
public float strafeSpeed = 10;
public float strafeCoolDownDuration = .2f;
private float strafeCoolDownTimer;
public float strafeCoolDownTimer;
public ForceMode strafeForceMode = ForceMode.Impulse;
[Header("DASH")]

// public float standingForcePositionOffset = .5f;
void FixedUpdate()
{
if (groundCheck && !groundCheck.isGrounded)
{
AddFallingForce(rb);
// print("AddFallingForce");
}
strafeCoolDownTimer += Time.fixedDeltaTime;
if (!allowKeyboardInput)
{
return;

strafeCoolDownTimer += Time.fixedDeltaTime;
if (spinAttack)
{

if (groundCheck.isGrounded)
{
RunOnGround(rb, dir.normalized);
if (AnimateBodyMesh)
{
bodyMesh.localPosition = Vector3.zero +
Vector3.up * walkingAnimScale * walkingBounceCurve.Evaluate(
m_animateBodyMeshCurveTimer);
m_animateBodyMeshCurveTimer += Time.fixedDeltaTime;
}
// if (AnimateBodyMesh)
// {
// bodyMesh.localPosition = Vector3.zero +
// Vector3.up * walkingAnimScale * walkingBounceCurve.Evaluate(
// m_animateBodyMeshCurveTimer);
// m_animateBodyMeshCurveTimer += Time.fixedDeltaTime;
// }
// print("running");
}
else

}
else //is idle
{
if (AnimateBodyMesh)
{
bodyMesh.localPosition = Vector3.zero;
}
}
// else //is idle
// {
//
//
// }
if (inputH == 0 && inputV == 0)
{

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

public void Strafe(Vector3 dir)
{
if (strafeCoolDownTimer > strafeCoolDownDuration)
if (dir != Vector3.zero && strafeCoolDownTimer > strafeCoolDownDuration)
{
rb.velocity = Vector3.zero;
rb.AddForce(dir.normalized * strafeSpeed, strafeForceMode);

public void RunOnGround(Rigidbody rb, Vector3 dir)
{
var vel = rb.velocity.magnitude;
float adjustedSpeed = Mathf.Clamp(agentRunSpeed - vel, 0, agentTerminalVel);
rb.AddForce(dir.normalized * adjustedSpeed,
runningForceMode);
// rb.AddForceAtPosition(dir.normalized * adjustedSpeed,transform.TransformPoint(Vector3.forward * standingForcePositionOffset),
// runningForceMode);
if (dir == Vector3.zero)
{
if (AnimateBodyMesh)
{
bodyMesh.localPosition = Vector3.zero;
}
}
else
{
var vel = rb.velocity.magnitude;
float adjustedSpeed = Mathf.Clamp(agentRunSpeed - vel, 0, agentTerminalVel);
rb.AddForce(dir.normalized * adjustedSpeed,
runningForceMode);
if (AnimateBodyMesh)
{
bodyMesh.localPosition = Vector3.zero +
Vector3.up * walkingAnimScale * walkingBounceCurve.Evaluate(
m_animateBodyMeshCurveTimer);
m_animateBodyMeshCurveTimer += Time.fixedDeltaTime;
}
// rb.AddForceAtPosition(dir.normalized * adjustedSpeed,transform.TransformPoint(Vector3.forward * standingForcePositionOffset),
// runningForceMode);
}
}
public void RunInAir(Rigidbody rb, Vector3 dir)

74
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/FPSAgent.cs


{
private AgentCubeMovement m_CubeMovement;
public GunController gunController;
public MultiGunAlternating gunController;
bool m_Shoot;
// bool m_Shoot;
private Camera m_Cam;
// Start is called before the first frame update

// sensor.AddObservation(localVelocity.x);
// sensor.AddObservation(localVelocity.z);
// sensor.AddObservation(m_Frozen);
sensor.AddObservation(m_Shoot);
sensor.AddObservation(m_ShootInput);
}
// else if (useVectorFrozenFlag)
// {

// if (!m_Frozen)
// {
// var shootCommand = false;
var forwardAxis = act[0];
var rightAxis = act[1];
var rotateAxis = act[2];
var shootAxis = act[3];
m_Shoot = shootAxis > 0 ? true : false;
// var forwardAxis = act[0];
// var rightAxis = act[1];
// var rotateAxis = act[2];
// var shootAxis = act[3];
// m_Shoot = shootAxis > 0;
// m_CubeMovement.RotateBody(rotateAxis, forwardAxis);
// m_CubeMovement.RunOnGround(m_AgentRb, m_Cam.transform.TransformDirection(new Vector3(0, 0, forwardAxis)));
// m_CubeMovement.Strafe(transform.right * rightAxis);
m_CubeMovement.RotateBody(rotateAxis, forwardAxis);
m_CubeMovement.RunOnGround(m_AgentRb, m_Cam.transform.TransformDirection(new Vector3(0, 0, forwardAxis)));
m_CubeMovement.Strafe(transform.right * rightAxis);
if (shootAxis > 0)
m_InputV = act[0];
m_InputH = act[1];
m_Rotate = act[2];
m_ShootInput = act[3];
m_CubeMovement.RotateBody(m_Rotate, m_InputV);
m_CubeMovement.RunOnGround(m_AgentRb, m_Cam.transform.TransformDirection(new Vector3(0, 0, m_InputV)));
// if (m_InputH != 0)
// {
m_CubeMovement.Strafe(transform.right * m_InputH);
// }
if (m_ShootInput > 0)
// gunController.Shoot();
gunController.Shoot();
if (m_AgentRb.velocity.sqrMagnitude > 25f) // slow it down
{
m_AgentRb.velocity *= 0.95f;
}
// if (m_AgentRb.velocity.sqrMagnitude > 25f) // slow it down
// {
// m_AgentRb.velocity *= 0.95f;
// }
}

MoveAgent(actionBuffers.ContinuousActions);
}
private float m_InputH;
private float m_InputV;
private float m_Rotate;
private float m_ShootInput;
void Update()
{
m_InputV = Input.GetKey(KeyCode.W) ? 1 : Input.GetKey(KeyCode.S) ? -1 : 0; //inputV
// m_InputH = 0;
// m_InputH += Input.GetKeyDown(KeyCode.Q) ? -1 : 0;
// m_InputH += Input.GetKeyDown(KeyCode.E) ? 1 : 0;
m_InputH = Input.GetKey(KeyCode.E) ? 1 : Input.GetKey(KeyCode.Q) ? -1 : 0; //inputH
// m_InputH = Input.GetKeyDown(KeyCode.E) ? 1 : Input.GetKeyDown(KeyCode.Q) ? -1 : 0; //inputH
m_Rotate = Input.GetKey(KeyCode.D) ? 1 : Input.GetKey(KeyCode.A) ? -1 : 0; //rotate
m_ShootInput = Input.GetKey(KeyCode.J) ? 1 : 0; //shoot
}
contActionsOut[0] = Input.GetKey(KeyCode.W) ? 1 : Input.GetKey(KeyCode.S) ? -1 : 0; //inputV
contActionsOut[1] = Input.GetKeyDown(KeyCode.E) ? 1 : Input.GetKeyDown(KeyCode.Q) ? -1 : 0; //inputH
contActionsOut[2] = Input.GetKey(KeyCode.D) ? 1 : Input.GetKey(KeyCode.A) ? -1 : 0; //rotate
contActionsOut[3] = Input.GetKey(KeyCode.Space) ? 1 : 0; //shoot
contActionsOut[0] = m_InputV; //inputV
contActionsOut[1] = m_InputH; //inputH
contActionsOut[2] = m_Rotate; //rotate
contActionsOut[3] = m_ShootInput; //shoot
// contActionsOut[0] = Input.GetKey(KeyCode.W) ? 1 : Input.GetKey(KeyCode.S) ? -1 : 0; //inputV
// contActionsOut[1] = Input.GetKeyDown(KeyCode.E) ? 1 : Input.GetKeyDown(KeyCode.Q) ? -1 : 0; //inputH
// contActionsOut[2] = Input.GetKey(KeyCode.D) ? 1 : Input.GetKey(KeyCode.A) ? -1 : 0; //rotate
// contActionsOut[3] = Input.GetKey(KeyCode.Space) ? 1 : 0; //shoot
}

4
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GunController.cs


public class GunController : MonoBehaviour
{
public bool StandbyMode; //this mode ignores player input
public bool AllowKeyboardInput = true; //this mode ignores player input
private bool initialized; //has this robot been initialized
public KeyCode shootKey = KeyCode.J;
[Header("AUTOSHOOT")] public bool autoShootEnabled;

void Update()
{
if (StandbyMode)
if (!AllowKeyboardInput)
{
return;
}

28
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/MultiGunAlternating.cs


public class MultiGunAlternating : MonoBehaviour
{
[Header("INPUT")] public bool AllowKeyboardInput = true;
public KeyCode shootKey = KeyCode.J;
[Header("AUTOSHOOT")] public bool autoShootEnabled;

shootTimer = 0;
}
void FixedUpdate()
public void Shoot()
if (autoShootEnabled)
{
ShootGunAtIndex(currentGunIndex);
}
if (Input.GetKey(shootKey))
{
ShootGunAtIndex(currentGunIndex);
}
ShootGunAtIndex(currentGunIndex);
}
}
void FixedUpdate()
{
// coolDownComplete = shootTimer > shootingRate;
// if (coolDownComplete)
// {
if (autoShootEnabled)
{
ShootGunAtIndex(currentGunIndex);
}
if (AllowKeyboardInput && Input.GetKey(shootKey))
{
ShootGunAtIndex(currentGunIndex);
// }
shootTimer += Time.fixedDeltaTime;
}

正在加载...
取消
保存