【发布时间】:2021-11-02 18:31:51
【问题描述】:
我对统一比较陌生,我有一个脚本可以与我的刚体一起工作,该刚体连接到一个球体对象。问题是球体不会朝我的电影摄影机所面对的方向移动,它当然只会朝最初设置的方向移动。如何让我的球体的 WASD 控件在相机所面对的方向上起作用?
这是我的动作脚本:
public class BallControl2 : MonoBehaviour {
public float speed = 2;
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float movementHorizontal = Input.GetAxis("Horizontal");
float movementVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(movementHorizontal, 0.0f, movementVertical).normalized;
rb.AddForce(movement * speed);
} }
【问题讨论】: