Unity3D——键盘控制移动

public float speed = 6f;
Vector3 movement;


void FixedUpdate () {orm

float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Move(h,v);
}it

void Move(float h,float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
GetComponent<Rigidbody>().MovePosition(movement+transform.position);//当前位置+移动的位置
// transform.position = movement + transform.position;//与上一行同样的方法io


}form

相关文章
相关标签/搜索