플레이어의 애니메이션이 이런식으로 구현이 되어있는데
멈추지 않으면 무브를 유지해야하는데 아무것도 걸어주지 않으니 자꾸 IDLE와 같이 애니메이션이 재생된다.
애니 스테이트에서 각 방향으로 의 무브의 움직임들은 트랜지션이 H또는 V AxisRaw라는 int 변수를 통해 제어되고 있고
움직이는동안에는 idle가 실행되지 않도록 isIdle 라는 bool 값을 넣어 주어서 H와 V AxisRaw가 0일때만 돌아가게
if (anim.GetInteger("hAxisRaw") != h)
{
anim.SetInteger("hAxisRaw", (int)h);
}else if (anim.GetInteger("vAxisRaw") != v)
{
anim.SetInteger("vAxisRaw", (int)v);
}
이상태의 코드를
//애니메이션
if (anim.GetInteger("hAxisRaw") != h)
{
anim.SetBool("isIdle", false);
anim.SetInteger("hAxisRaw", (int)h);
}else if (anim.GetInteger("vAxisRaw") != v)
{
anim.SetBool("isIdle", false);
anim.SetInteger("vAxisRaw", (int)v);
}
else
anim.SetBool("isIdle", true);
이렇게 수정해보니 update에 있어서 체크가 해제되는게 거의 한프레임이다
그래서 동작에 영향을 받는지 확인하기 위해
if (anim.GetInteger("hAxisRaw") != h)
{
anim.SetBool("isIdle", false);
anim.SetInteger("hAxisRaw", (int)h);
}else if (anim.GetInteger("vAxisRaw") != v)
{
anim.SetBool("isIdle", false);
anim.SetInteger("vAxisRaw", (int)v);
}
if(anim.GetInteger("hAxisRaw") == 0 && anim.GetInteger("vAxisRaw") == 0)
{
anim.SetBool("isIdle", true);
}
else
{
anim.SetBool("isIdle", false);
}
이렇게 수정하니 동작한다
그런데 이젠 horizontal과 vertical이 동시에 눌렸을때 (상,좌또는우),(하,좌또는우)
애니매이션이 도리도리를 한다 ....

일단
if (anim.GetInteger("hAxisRaw") != h&& anim.GetInteger("vAxisRaw") == 0)
{
anim.SetInteger("hAxisRaw", (int)h);
}else if (anim.GetInteger("vAxisRaw") != v && anim.GetInteger("hAxisRaw") == 0)
{
anim.SetInteger("vAxisRaw", (int)v);
}
//애니메이션 idle 상태를 파악
if(anim.GetInteger("hAxisRaw") == 0 && anim.GetInteger("vAxisRaw") == 0)
{
anim.SetBool("isIdle", true);
}
else
{
anim.SetBool("isIdle", false);
}
이렇게 수정을 해주어 도리도리는 멈췄는데 위를 바라본채로 가로로 이동을한다 이것도 막아야겠다.
한두시간 삽질 했는데 .. 모르겠다 ...ㅠㅠ 더 찾아봐야겠다
'Unity공부' 카테고리의 다른 글
2D TOPDOWN 오브젝트,NPC (0) | 2023.04.25 |
---|---|
2D TOPDOWN(플레이어) (0) | 2023.04.24 |
Unity 2D 기초 (0) | 2023.04.19 |
유니티 충돌 제어 및 트리거 이벤트 (0) | 2023.04.17 |
유니티 오브젝트 조작하기 vector3 (0) | 2023.04.17 |