I’m making a 2D game and I’m working on controlling the character to attack in 4 directions (up, down, left, right) and I’m having a problem. When moving in 4 directions, the attack animation is still normal, but when moving diagonally, the weapon has an error and doesn’t slash in the direction of the character. Can you tell me what the problem is?
- GIF - Imgur
- GIF - Imgur
Sounds like you wrote a bug… and that means… time to start debugging!
Anything with Animations / Animators / Mechanim:
Only consider the code AFTER you have done this critical step:
Always start with the Animator state machine and prove it works in isolation, no code at all.
Here’s more reading:
Once you are convinced your animator is perfect… move onto debugging the code:
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.