Unity第一人稱鏡頭控制器

	void FixedUpdate(){
		float h =Input.GetAxisRaw ("Horizontal");
		float v =Input.GetAxisRaw ("Vertical");

		Vector3 _xMov, _zMov;
		_xMov = transform.right * h;
		_zMov = transform.forward * v;

		movement = (_xMov + _zMov) * 2f;

		playerRigidbody.MovePosition (transform.position + movement*Time.fixedDeltaTime);
	

		float _yRot = Input.GetAxisRaw ("Mouse X");
	
		Vector3 _rotation = new Vector3 (0f, _yRot, 0f)*lookRotation;
		playerRigidbody.MoveRotation (playerRigidbody.rotation * Quaternion.Euler (_rotation));
	
		float _xRot = Input.GetAxisRaw ("Mouse Y")*lookRotation;


		currentCameraRotationX -= _xRot;
		currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, -lookLimitRotation, lookLimitRotation);

		//Apply our rotation to the transform of our camera
		cam.transform.localEulerAngles = new Vector3(currentCameraRotationX, 0f, 0f);
	
	}


這個情況是把鏡頭放到人物身上,但在對鏡頭轉動X的時候,是隻轉動鏡頭,人物本身不轉動。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章