Before the first tilt, the mouse moves well in all directions, but if you use the tilt, the mouse doesn’t move vertically, so please solve it.
it was my mistake
/*
incliation = lean, tilt
incl = incliation
*/
private bool isIncl = false;
//앉았을 때 얼마나 앉을지 결정하는 변수
[SerializeField]
private float crouchPosY;
private float originPosY;
private float originPosX;
private float originRotZ;
private float originRotX;
private float applycrouchPosY;
[SerializeField]
private float incliationPosX;
[SerializeField]
private float incliationRotZ;
private float applyInclRotZ;
private float applyInclPosX;
private float applyInclPosY;
private float applyInclRotX;
private CapsuleCollider capsuleCollider;
//민감도
[SerializeField]
private float lookSensitivityX;
[SerializeField]
private float lookSensitivityY;
//카메라 한계
[SerializeField]
private float cameraRotationLimit;
private float currentCameraRotationX = 0;
private float currentCameraRotationY = 0;
//필요한 컴퍼넌트
[SerializeField]
private Camera theCamera;
private Rigidbody myRigid;
// Start is called before the first frame update
void Start()
{
capsuleCollider = GetComponent<CapsuleCollider>();
myRigid = GetComponent<Rigidbody>();
applySpeed = walkSpeed;
//초기화
originPosX = theCamera.transform.localPosition.x;
originPosY = theCamera.transform.localPosition.y;
originRotZ = theCamera.transform.localRotation.z;
originRotX = theCamera.transform.localRotation.y;
applycrouchPosY = originPosY;
}
// Update is called once per frame
void Update()
{
TryIncl();
IsGround();
TryJump();
TryRun();
TryCrouch();
Move();
CameraRotation();
CharacterRotation();
applyInclRotX = theCamera.transform.localRotation.x;
}
private void TryIncl()
{
if (Input.GetKeyDown(KeyCode.Q))
{
Incliation();
}
if (Input.GetKeyDown(KeyCode.E))
{
}
}
private void Incliation()
{
isIncl = !isIncl;
if (isIncl)
{
applyInclPosX = incliationPosX;
applyInclRotZ = incliationRotZ;
}
else
{
applyInclPosX = originPosX;
applyInclRotZ = originRotZ;
}
StartCoroutine(InclCoroutine());
}
IEnumerator InclCoroutine()
{
float PosX = theCamera.transform.localPosition.x;
float RotZ = theCamera.transform.localRotation.z;
int count = 0;
while(PosX != applyInclPosX)
{
count++;
PosX = Mathf.Lerp(PosX, applyInclPosX, 0.06f);
theCamera.transform.localPosition = new Vector3(PosX, theCamera.transform.localPosition.y, theCamera.transform.localPosition.z);
yield return null;
if(count > 15)
{
break;
}
}
while(RotZ != applyInclRotZ)
{
RotZ = Mathf.Lerp(RotZ, applyInclRotZ, 0.06f);
Vector3 incl_v = new Vector3(theCamera.transform.localRotation.x, theCamera.transform.localRotation.y, RotZ);
theCamera.transform.localRotation = Quaternion.Euler(incl_v);
yield return null;
}
theCamera.transform.localPosition = new Vector3(applyInclPosX, 1, 0);
theCamera.transform.localRotation = Quaternion.Euler(theCamera.transform.localRotation.x, 0, RotZ);
}