浏览代码

health bar working now. move input to FU

/hh-develop-fps_game_project
HH 4 年前
当前提交
63381e18
共有 3 个文件被更改,包括 38 次插入43 次删除
  1. 51
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  2. 8
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentHealth.cs
  3. 22
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/FPSAgent.cs

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


m_LocalScale: {x: 2, y: 6, z: 10}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &314099675
GameObject:

- {fileID: 1028612599}
- {fileID: 1636260633}
m_Father: {fileID: 1817059483}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &338705764
GameObject:

m_LocalScale: {x: 15.124001, y: 0.27402976, z: 3.4036505}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &459618380
GameObject:

m_Direction: 0
m_MinValue: 0
m_MaxValue: 100
m_WholeNumbers: 0
m_Value: 97.6
m_WholeNumbers: 1
m_Value: 100
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []

- {fileID: 277357819}
- {fileID: 849921574}
m_Father: {fileID: 1817059483}
m_RootOrder: 10
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &849921573
GameObject:

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

m_LocalScale: {x: 15.124001, y: 10, z: 12.374001}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &984743962
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 530398460}
- {fileID: 1254413879}
- {fileID: 1817059483}
m_Father: {fileID: 0}
m_RootOrder: 14

- {fileID: 1680014532}
- {fileID: 1301582495}
- {fileID: 2074207738}
m_Father: {fileID: 1817059483}
m_RootOrder: 0
m_Father: {fileID: 1055797308}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1301582494
GameObject:

- {fileID: 607115666}
- {fileID: 613092657}
m_Father: {fileID: 1817059483}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1636260632
GameObject:

m_LocalScale: {x: 10, y: 10, z: 10}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1793097525
GameObject:

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: 1846705532}
- {fileID: 802143322}
m_Father: {fileID: 1055797308}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1828481691
GameObject:

m_LocalScale: {x: 15.124001, y: 10, z: 12.374001}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 9
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1966884490
GameObject:

m_LocalScale: {x: 10, y: 10, z: 10}
m_Children: []
m_Father: {fileID: 1817059483}
m_RootOrder: 8
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2074207737
GameObject:

m_EditorClassIdentifier:
currentHealth: 100
damagePerHit: 5
UISlider: {fileID: 459618382}
--- !u!1 &383863186595849764
GameObject:
m_ObjectHideFlags: 0

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &763385666061857549
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1479187681323959706}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9227871cd6ab8429d90afa4a5160924e, type: 3}
m_Name:
m_EditorClassIdentifier:
currentHealth: 0
damagePerHit: 0
--- !u!114 &1098949599672908312
MonoBehaviour:
m_ObjectHideFlags: 0

m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 80
m_CollisionDetection: 3
m_CollisionDetection: 2
--- !u!65 &1479187681323959703
BoxCollider:
m_ObjectHideFlags: 0

- component: {fileID: 1479187681323959703}
- component: {fileID: 1479187681323959700}
- component: {fileID: 1479187681323959697}
- component: {fileID: 763385666061857549}
- component: {fileID: 1479187681323959777}
- component: {fileID: 1479187681323959776}
- component: {fileID: 2669850465594241540}

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

8
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentHealth.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AgentHealth : MonoBehaviour
{

public Slider UISlider;
void Start()
void OnEnable()
currentHealth = 100;
UISlider.value = currentHealth;
}
// Update is called once per frame

if (col.transform.CompareTag("projectile"))
{
currentHealth -= damagePerHit;
UISlider.value = currentHealth;
}
}
}

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


Rigidbody m_AgentRb;
// bool m_Shoot;
private Camera m_Cam;
[Header("HEALTH")] public AgentHealth agentHealth;
// Start is called before the first frame update
public override void Initialize()

}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.CompareTag("projectile"))
{
//IMPLEMENT HEALTH MECHANIC
}
}
// void OnCollisionEnter(Collision col)
// {
// if (col.gameObject.CompareTag("projectile"))
// {
// //IMPLEMENT HEALTH MECHANIC
// }
// }
public override void OnActionReceived(ActionBuffers actionBuffers)
{

private float m_Rotate;
private float m_ShootInput;
void Update()
void FixedUpdate()
{
m_InputV = Input.GetKey(KeyCode.W) ? 1 : Input.GetKey(KeyCode.S) ? -1 : 0; //inputV
// m_InputH = 0;

// 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_Rotate = 0;
m_Rotate += Input.GetKey(KeyCode.A) ? -1 : 0;
m_Rotate += Input.GetKey(KeyCode.D) ? 1 : 0;
// m_Rotate = Input.GetKey(KeyCode.D) ? 1 : Input.GetKey(KeyCode.A) ? -1 : 0; //rotate
m_ShootInput = Input.GetKey(KeyCode.J) ? 1 : 0; //shoot
}

正在加载...
取消
保存