Today, I've met strange behavior in unity 3D mode. Currently developing the 3D game such as FPS type of game.
Here is basic code.
The problem happened when press Left, Right key several times after. My player continues rotating even if release left, right key.
private void MoveByPad()
{
float h = CnInputManager.GetAxisRaw("Horizontal");
float v = CnInputManager.GetAxisRaw("Vertical");
if (v > 0)
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
else if (v < 0)
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if (h < 0)
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
else if (h > 0)
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}
To solve the issue. Append code to stop the angular velocity to set zero.
Check 'Red marked' code
private void MoveByPad()
{
float h = CnInputManager.GetAxisRaw("Horizontal");
float v = CnInputManager.GetAxisRaw("Vertical");
if (v > 0)
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
else if (v < 0)
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if (h < 0)
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
else if (h > 0)
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
else
{
rb.angularVelocity = new Vector3(0, 0, 0);
}
}
Remember that this way is not going to work player need to rotation effect by some other factor.
By this reason, this is temporary code.
Is anybody knows this issue and the best way to solve the issue?
'개발 > 정보' 카테고리의 다른 글
유니티 앱배포전에 꼭 해야할일 - 앱평가 (Rating) 간단하게 구현하기 (0) | 2017.06.13 |
---|---|
Unity Button에 AddListener 직접구현하는 방법 (0) | 2017.06.13 |
유니티에 Admob 광고 간단하게 구현하는 방법 (Singleton pattern 사용) (0) | 2017.06.12 |
유니티에서 PC, Max & Linux Standalone 항목이 사라졌어요 (0) | 2017.06.12 |
유니티 컴파일 오류 해결 방법 (Unable to install APK to device. Please make sure the Android SDK) (4) | 2017.05.29 |
유니티 케릭터 회전 계속될 경우 중지하는 방법 (0) | 2017.05.18 |
유니티 네트워크 문제 - 클라이언트 위치정보 업데이트 안됨 (1) | 2017.05.17 |
유니티게임 소스코드 '집나간 원숭이' 개발중 코드 공개 (22) | 2017.05.04 |
최근댓글