Forum rules - please read before posting.

Rotation animation in 2d character movement

2»

Comments

  • edited February 2018
    Or maybe to have more snaping angles but always to end at some 45 angles.
  • The script will indeed snap the BodyAngle_Snapped parameter to 45 degrees - I was under the impression you wanted access to both a "snapped" value and a regular one.

    As the script is isolated from AC, it can always be amended to suit your needs, but I don't follow what you mean.  If you can give a clear example - ideally with images that demonstrate - of what it is exactly you want, I can try to help further.
  • edited February 2018
    This is how I think parameter should work:

      When character starts to rotate parameter is changing value (it doesnt snap), when rotation ends at
    some value, it snaps to the nearest 45 angle. 
      But if it would be possible to make this snap not be instantenious, but to have changing value when it is going toward nearest 45 angle. So when rotation ends before or after nearest 45 angle parameter is still continuosly changing value until it reaches nearest 45 angle. In reality character has ended rotation at some angle that is not at 45, but parameter is no longer connected to rotation but is changing value to end at 45 angle.
     I hope this is not to complex...
  • It is, but I think it could still be achieved with a separate script.

    Try this:
    http://pasteall.org/816471/csharp

    A bit rough around the edges, and the "Correction speed" might need tweaking, but is that more like it?
  • I am doing more testing but I think that is it.
    Thank you very much!

    I noticed some problem that has nothing to do with your script.
    Turn float is acting as expected when character starts to move. When rotation starts, turn float is 1 or -1 when character starts to move it becomes 0. But if character has to do pathfinding , for example has to rotate to avoid hole, during rotation Turn float remains to be 0. 
  • As I said earlier, the turn float is only set when the character is idle (and so turning on the spot).  If you want a "true" turn speed, you can read the character script's GetTurnFloat method and set it to a separate float parameter.

    This is what the script above also does when setting the value of "isTurningRight".
  • Ah, ok it seems I missed that...

    Again thank you very much for helping me.

    Only one more question:
      Is it possible to make character start moving when BodyAngle_Snapped get final value (some 45 angle) and not when turn float becomes 0.
  • A lot more tricky, but may be possible via an external script.

    Basically you can try setting the Player component's "Motion control" to "Manual" when you don't want him to move, and back to "Automatic" when you're ready to have him continue moving:

    character.motionControl = MotionControl.Manual;
  • Thanks, I will try it.
  • I was doing more testing of a script and i noticed that from time to time character starts to rotate in opposite direction slightly, than it starts to rotate where it should.
    It is like it is doing angle correction from the start but in opposite direction of intendent rotation.  
  • edited February 2018
    The original body angle, or the one set in the script?  It'll likely need tweaking to get exactly right.  Under what situation does this occur, exactly?
  • edited February 2018
    Body angle set in script (BodyAngle_Snapped). It happens exactly on start of rotation, but not always.
     I am trying to determine what combination of BodyAngle and BodyAngle_Snapped causes problem.
  • Sorry I am very bad at scripting. 
    How do I get float parameter in animator for GetTurnFloat, so I can get true turn speed?

  • As reading and writing animator parameters are part of Unity, you can get references and examples in the official Unity documentation:

    https://docs.unity3d.com/ScriptReference/Animator.SetFloat.html
    https://docs.unity3d.com/ScriptReference/Animator.GetFloat.html
  • I managed to get parameter in animator for turn float.

      I am now trying to use character.motionControl = MotionControl.Manual; to stop motion of character when i want. But it seems that this stops character completely. 
     What i need is that character is allowed to rotate and translation is what i want to control. Is this possible?
  • Have you tried the MotionControl.JustTurning option?  That will prevent the character from moving, but AC will still handle spot-turning.
  • No I didnt. I am trying it now .Thanks.
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.