浏览代码

add strafe

/hh-develop-fps_game_project
HH 4 年前
当前提交
50365b74
共有 3 个文件被更改,包括 164 次插入34 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/Projectile.prefab
  2. 17
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  3. 179
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentCubeMovement.cs

2
Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/Projectile.prefab


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
serializedVersion: 2
m_Mass: 10
m_Mass: 2
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 0

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


m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1517390719, guid: 497c5a1fa56ff4204a66acfb42a8ebde, type: 3}
propertyPath: m_LocalRotation.x
value: 0.087676235
objectReference: {fileID: 0}
- target: {fileID: 1517390719, guid: 497c5a1fa56ff4204a66acfb42a8ebde, type: 3}
propertyPath: m_LocalRotation.y
value: -0.0000000039375903
objectReference: {fileID: 0}
- target: {fileID: 1517390719, guid: 497c5a1fa56ff4204a66acfb42a8ebde, type: 3}
propertyPath: m_LocalRotation.z
value: 3.4656758e-10
objectReference: {fileID: 0}
- target: {fileID: 2170513384791859414, guid: 497c5a1fa56ff4204a66acfb42a8ebde,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: cam
value:
objectReference: {fileID: 1828481695}
- target: {fileID: 2170513384791859415, guid: 497c5a1fa56ff4204a66acfb42a8ebde,
type: 3}
propertyPath: agentRotationSpeed
value: 300
objectReference: {fileID: 0}
- target: {fileID: 2170513384791859417, guid: 497c5a1fa56ff4204a66acfb42a8ebde,
type: 3}
propertyPath: m_Name

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


public float agentFallingSpeed = 50f;
public Camera cam;
private Vector3 lookDir;
private float lookDir;
private float inputH;
private float inputV;
void Awake()
{
rb = GetComponent<Rigidbody>();

var camForward = cam.transform.forward;
camForward.y = 0;
var camRight = cam.transform.right;
lookDir = Vector3.zero;
lookDir += Input.GetKey(KeyCode.D) ? Vector3.right : Vector3.zero;
lookDir += Input.GetKey(KeyCode.W) ? Vector3.forward : Vector3.zero;
lookDir += Input.GetKey(KeyCode.A) ? Vector3.left : Vector3.zero;
lookDir += Input.GetKey(KeyCode.S) ? Vector3.back : Vector3.zero;
// lookDir = Vector3.zero;
// lookDir += Input.GetKey(KeyCode.W) ? Vector3.forward : Vector3.zero;
// lookDir += Input.GetKey(KeyCode.S) ? Vector3.back : Vector3.zero;
// lookDir += Input.GetKey(KeyCode.D) ? Vector3.right : Vector3.zero;
// lookDir += Input.GetKey(KeyCode.A) ? Vector3.left : Vector3.zero;
//BODY ROTATION
lookDir = Input.GetAxis("Horizontal");
//FORWARD MOVEMENT
inputV = Input.GetAxis("Vertical");
//LATERAL MOVEMENT
inputH = 0;
inputH += Input.GetKey(KeyCode.Q) ? -1 : 0;
inputH += Input.GetKey(KeyCode.E) ? 1 : 0;
// lookDir = Input.GetKey(KeyCode.A)?
// var moveLateral = Vector3.zero;
// //FORWARD MOVEMENT
// moveforward += Input.GetKey(KeyCode.W) ? Vector3.forward : Vector3.zero;
// moveforward += Input.GetKey(KeyCode.S) ? Vector3.back : Vector3.zero;
//
// //LATERAL MOVEMENT
// moveLateral += Input.GetKey(KeyCode.Q) ? Vector3.right : Vector3.zero;
// moveLateral += Input.GetKey(KeyCode.E) ? Vector3.left : Vector3.zero;
//
// //BODY ROTATION
// lookDir += Input.GetKey(KeyCode.D) ? Vector3.right : Vector3.zero;
// lookDir += Input.GetKey(KeyCode.A) ? Vector3.left : Vector3.zero;
if (Input.GetKeyDown(KeyCode.Space))
{

}
spinAttack = Input.GetKey(KeyCode.H);
dashPressed = Input.GetKeyDown(KeyCode.K);
if (dashPressed)
{

// rb.AddTorque(Vector3.up * spinAttackSpeed);
rb.angularVelocity = Vector3.up * spinAttackSpeed;
}
if (lookDir != Vector3.zero)
{
// var camRotDir = lookDir;
// camRotDir.z = Mathf.Clamp01(camRotDir.z);
// var rot = quaternion.LookRotation(camRotDir, Vector3.up);
var allMoveInput = inputH + inputV;
if (allMoveInput != 0)
{
var dir = cam.transform.TransformDirection(lookDir);
dir.y = 0;
var rot = quaternion.LookRotation(dir, Vector3.up);
if (!spinAttack)
var dir = cam.transform.TransformDirection(new Vector3(inputH, 0, inputV));
// dir.y = 0;
//HANDLE WALKING
if (groundCheck.isGrounded)
rb.rotation = Quaternion.Lerp(rb.rotation, rot, agentRotationSpeed * Time.fixedDeltaTime);
RunOnGround(rb, dir.normalized);
// RunOnGround(rb, dir.normalized);
// var dirToGo = rb.transform.forward;
var dirToGo = dir;
// RunOnGround(rb, dirToGo);
if (!groundCheck.isGrounded)
}
if (lookDir != 0)
{
if (!spinAttack)
// RunInAir(rb, dirToGo.normalized);
var rot = rb.rotation * Quaternion.Euler(0, lookDir * agentRotationSpeed * Time.fixedDeltaTime, 0);
rb.MoveRotation(rot);
// rb.rotation *= Quaternion.AngleAxis(); rb.rotation * Quaternion. (rb.rotation, rot, agentRotationSpeed * Time.fixedDeltaTime);
else
{
// var forwardMovement = lookDir;
//// forwardMovement.x = 0; //
// var walkDir = cam.transform.TransformDirection(forwardMovement);
// RunOnGround(rb, walkDir.normalized);
RunOnGround(rb, dirToGo.normalized);
}
// rb.MoveRotation(rb.rotation * Quaternion.AngleAxis(agentRotationSpeed, rotationAxis));
// if (lookDir != Vector3.zero)
// {
// // var camRotDir = lookDir;
// // camRotDir.z = Mathf.Clamp01(camRotDir.z);
// // var rot = quaternion.LookRotation(camRotDir, Vector3.up);
//
//
// var dir = cam.transform.TransformDirection(lookDir);
// dir.y = 0;
// var rot = quaternion.LookRotation(dir, Vector3.up);
// if (!spinAttack)
// {
// rb.rotation = Quaternion.Lerp(rb.rotation, rot, agentRotationSpeed * Time.fixedDeltaTime);
// }
// // RunOnGround(rb, dir.normalized);
// // var dirToGo = rb.transform.forward;
// var dirToGo = dir;
// // RunOnGround(rb, dirToGo);
// if (!groundCheck.isGrounded)
// {
// // RunInAir(rb, dirToGo.normalized);
// }
// else
// {
// // var forwardMovement = lookDir;
// //// forwardMovement.x = 0; //
// // var walkDir = cam.transform.TransformDirection(forwardMovement);
// // RunOnGround(rb, walkDir.normalized);
//
// RunOnGround(rb, dirToGo.normalized);
// }
// // rb.MoveRotation(rb.rotation * Quaternion.AngleAxis(agentRotationSpeed, rotationAxis));
// }
else //is idle
{
if (groundCheck && groundCheck.isGrounded && !dashPressed)

}
// void FixedUpdate()
// {
// if (spinAttack)
// {
// // rb.AddTorque(Vector3.up * spinAttackSpeed);
// rb.angularVelocity = Vector3.up * spinAttackSpeed;
// }
//
// //HANDLE WALKING
// if (groundCheck.isGrounded)
// {
// RunOnGround(rb, dirToGo.normalized);
// }
//
//
// if (lookDir != Vector3.zero)
// {
// // var camRotDir = lookDir;
// // camRotDir.z = Mathf.Clamp01(camRotDir.z);
// // var rot = quaternion.LookRotation(camRotDir, Vector3.up);
//
//
// var dir = cam.transform.TransformDirection(lookDir);
// dir.y = 0;
// var rot = quaternion.LookRotation(dir, Vector3.up);
// if (!spinAttack)
// {
// rb.rotation = Quaternion.Lerp(rb.rotation, rot, agentRotationSpeed * Time.fixedDeltaTime);
// }
// // RunOnGround(rb, dir.normalized);
// // var dirToGo = rb.transform.forward;
// var dirToGo = dir;
// // RunOnGround(rb, dirToGo);
// if (!groundCheck.isGrounded)
// {
// // RunInAir(rb, dirToGo.normalized);
// }
// else
// {
// // var forwardMovement = lookDir;
// //// forwardMovement.x = 0; //
// // var walkDir = cam.transform.TransformDirection(forwardMovement);
// // RunOnGround(rb, walkDir.normalized);
//
// RunOnGround(rb, dirToGo.normalized);
// }
// // rb.MoveRotation(rb.rotation * Quaternion.AngleAxis(agentRotationSpeed, rotationAxis));
// }
// else //is idle
// {
// if (groundCheck && groundCheck.isGrounded && !dashPressed)
// {
// AddIdleDrag(rb);
// }
// }
//
// if (groundCheck && !groundCheck.isGrounded)
// {
// AddFallingForce(rb);
// }
//
//
// }
public void Jump(Rigidbody rb)
{

正在加载...
取消
保存