我很團結,我決定做一個簡單的第一人稱遊戲,但是我的腳本只允許玩家四處看看,而不是移動。我已經使用了AddForce,但是我不確定我是否正確地做了。Unity C#第一人稱腳本不移動
public float walkSpeedForward = 5f;
public float walkSpeedStrafe = 4f;
public float walkSpeedBack = 3f;
public float sprintMultiplier = 2f;
public Camera cam;
public float sensitivityX = 0f;
public float sensitivityY = 0f;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
public Rigidbody rb;
float rotationY = 0f;
// Use this for initialization
void Awake() {
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;
}
// Update is called once per frame
void Update() {
float rotationX = cam.transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX;
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
cam.transform.localEulerAngles = (new Vector3(-rotationY, rotationX, 0f));
}
void FixedUpdate()
{
rb.AddForce (new Vector3 (Input.GetAxis ("Horizontal") * walkSpeedStrafe * Time.deltaTime, 0, Input.GetAxis ("Vertical") * walkSpeedForward * Time.deltaTime));
}
http://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html –