LoginSignup
1
0

FirstPersonControllerアセットを使用したPlayerの視点を外部から操作すると「視点がガクッとなる」問題の原因

Posted at

カットシーン等を作っていると、

「カットシーン後にプレイヤーを位置移動(テレポート)&視点を任意の方向に指定したい
といった場面が出てくると思います。

その際に視点を任意の方向に指定しようと「PlayerCameraRoot」にx座標をセットすると
マウスを操作出来るようになった最初の段階で「ガクッ」としないでしょうか?

FirstPersonController.cs
private void CameraRotation() 
		{
			// if there is an input
			if (_input.look.sqrMagnitude >= _threshold)
			{
				//Don't multiply mouse input by Time.deltaTime
				float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;

				_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier;
				_rotationVelocity = _input.look.x * RotationSpeed * deltaTimeMultiplier;

                // clamp our pitch rotation
                _cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp);

                // Update Cinemachine camera target pitch
                CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f);

                // rotate the player left and right
                transform.Rotate(Vector3.up * _rotationVelocity);
			}
		}

結論から申し上げると

・_cinemachineTargetPitch変数が前の視点情報のままで計算
・CinemachineCameraTarget.transform.localRotationでセット

となっている為、
カットシーン後等のマウスが効き始めた直後に前の視点情報で計算された値が
localRotationにセットされて「視点がガクッとなる」という問題が発生します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0