public float velcory = 10f;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent();
}
//网上的控制移动的几种方法
void FixedUpdate()
{
float h = Input.GetAxis(“Horizontal”);
float v = Input.GetAxis(“Vertical”);
Vector3 vel = GetComponent().velocity;
//transform.Translate(new Vector3(-v * Time.deltaTime * velcory,transform.position.y, h * Time.deltaTime * velcory));
//m_rigidbody.velocity += new Vector3(h, 0, v);
//m_rigidbody.AddForce(new Vector3(h,0,v)*speed);
//m_rigidbody.MovePosition(new Vector3(-3.76f,0,1.58f));
if (Mathf.Abs(h) > 0.05f || Mathf.Abs(v) > 0.05f)
{
this.GetComponent<Rigidbody>().velocity = new Vector3(-v * velcory, vel.y, h * velcory);//设置单位向量的速度和方向,使其移动
//new Vector3(h, 0,v );//单位向量ADSW移动的位置的方向
transform.rotation = Quaternion.LookRotation(new Vector3(-v, 0, h));//transform.rotation人物的朝向就是 单位向量ADSW移动的位置的方向
}
else //表示没有按下按键,h,v没有变化
{
if (agent.enabled==false)//并且没有在寻路的时候
{
GetComponent<Rigidbody>().velocity = Vector3.zero;//把刚体的速度设置为0
}
}
if (agent.enabled)//如果在寻路
{
transform.rotation = Quaternion.LookRotation(agent.velocity);
}
}
public float velcory = 10f;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent();
}
//网上的控制移动的几种方法
void FixedUpdate()
{
float h = Input.GetAxis(“Horizontal”);
flo