using UnityEngine;
public class TurnTest : MonoBehaviour
{
private Vector3 dir=new Vector3(0,0,-1);
private Quaternion qua;
private void Update()
{
float hor = Input.GetAxisRaw("Horizontal");
float ver = Input.GetAxisRaw("Vertical");
transform.position += transform.forward * Mathf.Abs(ver * Time.deltaTime*5) ;
transform.Rotate(0,hor*Time.deltaTime*100,0);
if (Input.GetKey(KeyCode.S)&&!(Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)))
{
qua = Quaternion.LookRotation(dir);
transform.rotation=Quaternion.Lerp(transform.rotation,qua,Time.deltaTime*10);
}
if (Input.GetKey(KeyCode.W)&&!(Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)))
{
qua = Quaternion.LookRotation(-dir);
transform.rotation=Quaternion.Lerp(transform.rotation,qua,Time.deltaTime*10);
}
}
}
3D物体移动代码
最新推荐文章于 2023-03-19 17:38:38 发布