기본 공격 구현

This commit is contained in:
2026-09-24 01:52:29 +09:00
parent 4a08a9d085
commit da4075e42e
36 changed files with 570 additions and 425 deletions

View File

@@ -230,14 +230,25 @@ private static AnimatorController BuildController(Dictionary<string, AnimationCl
{
name = "MoveY", type = AnimatorControllerParameterType.Float, defaultFloat = -1f
});
//공격은 대각선 4방향뿐이라 이동 방향과 파라미터를 나눈다.
//MoveX/MoveY를 그대로 쓰면 정면(상하좌우)을 볼 때 두 대각선 클립의 가중치가 같아져서
//어느 쪽이 나올지 알 수 없고, 공격이 끝난 뒤 바라보는 방향까지 대각선으로 틀어진다
controller.AddParameter(new AnimatorControllerParameter
{
name = "AttackX", type = AnimatorControllerParameterType.Float, defaultFloat = 0.7071f
});
controller.AddParameter(new AnimatorControllerParameter
{
name = "AttackY", type = AnimatorControllerParameterType.Float, defaultFloat = -0.7071f
});
controller.AddParameter("Speed", AnimatorControllerParameterType.Float);
controller.AddParameter("Attack", AnimatorControllerParameterType.Trigger);
controller.AddParameter("Roll", AnimatorControllerParameterType.Trigger);
AnimatorState idle = AddDirectionalState(controller, "Idle", Dirs8, d => clips["Idle_" + d]);
AnimatorState move = AddDirectionalState(controller, "Move", Dirs8, d => clips["Move_" + d]);
AnimatorState roll = AddDirectionalState(controller, "Roll", Dirs8, d => clips["Roll_" + d]);
AnimatorState slash = AddDirectionalState(controller, "Slash", Dirs4, d => clips["Slash_" + d]);
AnimatorState idle = AddDirectionalState(controller, "Idle", Dirs8, d => clips["Idle_" + d], "MoveX", "MoveY");
AnimatorState move = AddDirectionalState(controller, "Move", Dirs8, d => clips["Move_" + d], "MoveX", "MoveY");
AnimatorState roll = AddDirectionalState(controller, "Roll", Dirs8, d => clips["Roll_" + d], "MoveX", "MoveY");
AnimatorState slash = AddDirectionalState(controller, "Slash", Dirs4, d => clips["Slash_" + d], "AttackX", "AttackY");
AnimatorStateMachine stateMachine = controller.layers[0].stateMachine;
stateMachine.defaultState = idle;
@@ -316,14 +327,15 @@ private static void ClearController(AnimatorController controller)
/// <summary>8방향(혹은 4방향) 클립을 2D 블렌드 트리 하나로 묶은 스테이트를 만든다.</summary>
private static AnimatorState AddDirectionalState(AnimatorController controller, string name,
string[] dirs, Func<string, AnimationClip> pick)
string[] dirs, Func<string, AnimationClip> pick,
string paramX, string paramY)
{
AnimatorState state = controller.CreateBlendTreeInController(name, out BlendTree tree, 0);
tree.name = name;
tree.blendType = BlendTreeType.SimpleDirectional2D;
tree.blendParameter = "MoveX";
tree.blendParameterY = "MoveY";
tree.blendParameter = paramX;
tree.blendParameterY = paramY;
foreach (string dir in dirs)
{