Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

54 行
1.5 KiB

using System;
using UnityEngine;
using UnityEngine.Events;
public class PlayerMovePhysics : MonoBehaviour
{
public float speed = 5;
public bool worldDirection = true;
public bool rotatePlayer = true;
public Action spaceAction;
public Action enterAction;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
private void OnEnable()
{
transform.position += new Vector3(10, 0, 0);
}
void FixedUpdate()
{
Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//input = Vector3.forward;
if (input.magnitude > 0)
{
Vector3 fwd = worldDirection
? Vector3.forward : transform.position - Camera.main.transform.position;
fwd.y = 0;
fwd = fwd.normalized;
if (fwd.magnitude > 0.001f)
{
Quaternion inputFrame = Quaternion.LookRotation(fwd, Vector3.up);
input = inputFrame * input;
if (input.magnitude > 0.001f)
{
rb.AddForce(speed * input);
if (rotatePlayer)
transform.rotation = Quaternion.LookRotation(input.normalized, Vector3.up);
}
}
}
if (Input.GetKeyDown(KeyCode.Space) && spaceAction != null)
spaceAction();
if (Input.GetKeyDown(KeyCode.Return) && enterAction != null)
enterAction();
}
}