Forum rules - please read before posting.

Rotation animation in 2d character movement

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.
«1

Comments

  • As in, Broken Sword-style?

    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.
  • edited December 2017
    Yes just  like Broken Sword.

    I havent used sprites unity complex yet.
    I have read the instructions about sprites unity complex, but I do not understand is that mean that I do not need a special animation for rotation? Is animation controled with direction integer from 0 to 7 (8 animations) all I need to make rotation movement  smooth?
  • You can use a direction integer or an angle - it's up to you.  Essentially you can make as much or as little animation as you like - you can just have two (left + right) directions, or even up to 360.

    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
  • Thanks, I will try that.
  • edited January 2018
    I was studying Brain2D_SpritesUnityComplex and  I wold like to modify it so that I have rotation. Here  animations for idle, walk and talk are in blend trees.
     
    I need advice, do I put animation for rotation in separate blend tree made for rotation or do i put animation in existing blend trees?

    To recap, I would like rotation animation to happen before walking (activated option turn than move) 

    e.g. rotate from idle down right to idle down than walk down
  • If you define a "Turn float" parameter and list it in your Player's Inspector, then it'll take a value of +1 when turning clockwise, and -1 when anticlockwise.  Bear in mind that this is only the case when idle, so you'd want to have "Turn before walking?" checked as well.

    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.
  • Ok Thanks.

  •    I am trying to wire Brain2D_SpritesUnityComplex in Base layer and I have defined Turn float.
    Also I have activated "Turn before walking?". 
      I noticed that Turn float have value of 1 or -1 even during straight movement of character. When straight movement is over than Turn float becomes 0.
     I think that it is strange that turn float has value other than 0 when rotation is definitely over when turn before walking is activated.
  • Recreated, thanks - I'll look into it.
  • Ok.Thank you
  • edited February 2018
       Would it be possible to limit the movement of a character so that the rotation always ends with a discrete angle. For example, movement to be like queen moves in chess.So that faceAngle float would always end in some of this numbers:0,45,90,135....etc.
       The reason I think that would be good is because when you insert animations for rotation, you can never synchronize the actual rotation with rotation of animation. And this is because the rotation animation has a fixed duration and ends in fixed angle.
       This also would be good for character movement that do not use rotation animation because it would prevent gliding. For example it would prevent that sprite or animation for 90 angle is moving at 81.3 angle..
       This could be implemented as option for character movement which could be called "constraint movement" or something like that.
  • edited February 2018
    A feature in the upcoming v1.61.0 release is to allow "angle-snapping" of the facing angle float parameter - to either 90 or 45 degrees.  This is to allow for easier incorporation of Blend Trees without interpolation.

    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.
  • edited February 2018
    So this is new float angle paramater that is changing between 45 angles? And old float angle parameter determine at what angle character is actualy going? 
    If its like that, than that is exactly what I want (I can live with gliding). 
    I hope that snaping doesnt mean that new float angle parameter is jumping instantly at 45 angles because i want  to add more animations consisting of one frame in blend tree between 45 angles
  • It does mean that the existing parameter snaps, yes.  But this feature is really just a convenience tool - you can have a separate parameter that snaps to the nearest 45 degrees easily with a custom script attached.

    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.
  • Great, thanks!
    So when update is out than script will work and i will get new parameter? 
    Sorry i have no experience with scripting, where exactly should I put this script?
  • It's subject to change until the update is final, but that's generally the right approach.  I'll assist if it needs amendment.

    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.
  • Many thanks!
  • Hi,
    I have updated AC an now I am trying to make script that you provided to work, but have some trouble.
    I did all steps in your post.

    In Angle Snap component i added My character and My animator but now i dont know how to get parameter in animator. I have tryed to name parmeter in animator to  BodyAngle_Snapped just like in your script but it is always  0.0.
    What I am doing wrong?
  • Any messages in the Console?

    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.
  • edited February 2018
       I managed to make script work. In Mecanim parameters for Body angle float I have put BodyAngle and in animator I have put BodyAngle_Snapped parameter.
      But BodyAngle_Snapped behaves the same way as when I turn on Angle Snaping in Mecanim.  Or i did something wrong. 
      What I wanted is to have BodyAngle_Snapped to be at 45 angles but when character is rotating that i have also in between values so that i can put  1 frame animation in blend tree in between 45 angles. When I put in animator also BodyAngle parameter i have intermedium values but when rotation is over it doesnt end on some 45 angle.
     Sorry if I am boring you with this ,but I think that  I need some combination of these two parameters in one parameter.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.