Is it possible when inserting animations for character
movement in 2d, to somehow insert a character rotation animation between 2 directions? I have very smooth animation for 8 direction but when character is rotating it looks chopped because it has only 8 frames for full rotation.
Comments
You'll need to switch to the "Sprites Unity Complex" animation engine if you haven't already. It's covered in Section 3.3.3 of the Manual, but basically it causes animation playback to be based on parameter values that you define in the Inspector (for example, movement speed and facing angle).
How you use these parameters is up to you, but you can use this to create e.g. transitions between animations, or make use of turning-while-walking animations. This is opposed to the "Sprites Unity" engine's way of just playing animations by name, but allows for much more control. This way of working is more aligned with Unity "best practice" when it comes to Animator Controllers, so you can read more on them on Unity's website if you need a primer.
In the 2D Demo's Resources folder, you can find a Sprites Unity Complex variant of the Player prefab, Brain2D_SpritesUnityComplex. He is set up to work in 8 directions, but has instant transitions between them. If you want to add special turning animations, then you can add them in between, e.g. for walking right to down:
"Walk right" animation
If move speed > 0 and direction = 0, transition to:
"Turn walk right to down" animation
After animation completes, transition to:
"Walk down" animation
You'd probably be better off doing without an Idle Blend Tree and just having them all wired up in the base layer. That way, you can have the Idle_DR animation transition to Idle_D (via a turning animation) if TurnSpeed > 1, and then transition from Idle_D to Walk_D if MoveSpeed > 0.
There's not really a "correct vs incorrect way" here - it really comes down to your needs. Sprites Unity Complex mode is designed to give you the control over how your Controller is laid out, so I might not have the best suggestion. So far as I'm aware, this level of animation fidelity hasn't been covered on the forums before, so it could well take a bit of trial and error.
However, this only affects the animation - not the actual movement of the character. If it did, then characters would overshoot their destinations (both final, and pathfinding nodes) because this restriction would limit them from being able to get close enough. I think the only way to incorporate such behaviour would be to implement a custom pathfinding algorithm, so that the fixed angles come from the path nodes rather than a restriction of the character. The Manual's "Custom pathfinding" chapter covers how a custom algorithm can be incorporated if you'd like to attempt it.
The new code in the update will be in the form of a function that takes an angle and snaps it to the nearest 45 or 90 degrees, so you can use it to modify a second float parameter, e.g.:
http://pasteall.org/803944/csharp
That'll take the value of a "BodyAngle" parmaeter and use it to set the value of "BodyAngle_Snapped". Once the update is out, of course.
The script goes in a C# file with the same name as the "class" - AngleSnap in this case. In Unity's Project window, you'd create a new C# script named AngleSnap and overwrite its contents with the above script.
As the class derives from MonoBehaviour, it can be placed in your scene - meaning you can create a new empty GameObject, and add the script a a component to that object.
You need to have two parameters: BodyAngle and BodyAngle_Snapped. The script takes the former, snaps it to the nearest 45, and updates the latter.