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

相關文章
相關標籤/搜索