浏览代码

fixed strafe input issue

/hh-develop-fps_game_project
HH 4 年前
当前提交
669d4fc4
共有 4 个文件被更改,包括 140 次插入8 次删除
  1. 64
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  2. 54
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/FPSAgent.cs
  3. 19
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs
  4. 11
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs.meta

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


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1609129050}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1627753778
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1627753779}
m_Layer: 0
m_Name: GameController
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1627753779
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1627753778}
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: 2096682435}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1628638785
GameObject:
m_ObjectHideFlags: 0

solverIterations: 8
solverVelocityIterations: 8
reuseCollisionCallbacks: 1
--- !u!1 &2096682434
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2096682435}
m_Layer: 0
m_Name: =====MANAGERS=====
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2096682435
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2096682434}
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: 1627753779}
m_Father: {fileID: 0}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2144694764
GameObject:
m_ObjectHideFlags: 0

gunController: {fileID: 7759475058439974328}
useVectorObs: 1
agentHealth: {fileID: 235556834305398865}
m_InputH: 0
leftStrafe: 0
rightStrafe: 0
--- !u!114 &1543860467109742330
MonoBehaviour:
m_ObjectHideFlags: 0

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


m_CubeMovement.RunOnGround(m_AgentRb, m_Cam.transform.TransformDirection(new Vector3(0, 0, m_InputV)));
// if (m_InputH != 0)
// {
// if (leftStrafe)
// {
// m_CubeMovement.Strafe(transform.right * -1);
// leftStrafe = false;
// }
// if (rightStrafe)
// {
// m_CubeMovement.Strafe(transform.right * 1);
// rightStrafe = false;
// }
//
m_CubeMovement.Strafe(transform.right * m_InputH);
// }
if (m_ShootInput > 0)

// }
// 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;
public float m_InputH;
public bool leftStrafe;
public bool rightStrafe;
void Update()
{
// m_InputH = Input.GetKeyDown(KeyCode.K) ? 1 : Input.GetKeyDown(KeyCode.J) ? -1 : 0; //inputH
if (Input.GetKeyDown(KeyCode.K))
{
rightStrafe = true;
}
if (Input.GetKeyDown(KeyCode.J))
{
leftStrafe = true;
}
}
void FixedUpdate()
{

// m_InputH += Input.GetKeyDown(KeyCode.E) ? 1 : 0;
m_InputH = Input.GetKey(KeyCode.E) ? 1 : Input.GetKey(KeyCode.Q) ? -1 : 0; //inputH
m_ShootInput = Input.GetKey(KeyCode.J) ? 1 : 0; //shoot
m_ShootInput = Input.GetKey(KeyCode.Space) ? 1 : 0; //shoot
}
public override void Heuristic(in ActionBuffers actionsOut)

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

m_InputH = 0;
if (leftStrafe)
{
print("leftstrafe");
m_InputH += -1;
leftStrafe = false;
}
if (rightStrafe)
{
print("rightstrafe");
m_InputH += 1;
rightStrafe = false;
}
contActionsOut[1] = m_InputH; //inputH
}
}

19
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
// public List<
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

11
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs.meta


fileFormatVersion: 2
guid: 0617cba133bba4ad895f82b6d9665b59
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存