Forum rules - please read before posting.

Get characters velocity in Unity Units

Hello,
I'm making my own animation controller since I use Spine with various skeletons so I'm having trouble with characters velocity.
The accessible properties of the Char class itself don't give the actual velocity, I've debuged the "GetMoveSpeed()" Function itself and it gives confusing values that go from -0.1 to infinity.

How could I get the real velocity in Unity units that my character is moving at the time?

Thanks in advance.

Comments

  • A script could record the character's position each frame, and then divide the distance changed since the last frame by Time.deltaTime.
  • I though the characters velocity was stored in AC :)
    I'll give it a try and post the results, I hope it doesn't become too resource hungry for my proyect :(

    What does the "GetMoveSpeed()" function return then? I'm confused by it's tendency to reach infinity

  • It is the speed, just not in Unity units.  It probably shouldn't be reaching infinity though.  Can you post your full character Inspector?
  • Updates:
    Unfortunately I can't calculate the Velocity myself since I need to know the Velocity the character will move while walking and since the characters position is the same as idle when it starts walking the velocity will always be 0.
    How do you calculate the velocity the character needs to move depending on where it is?
    I could take that as my velocity parameter.
    Thank you so much.
  • Again, I'll need to see your Inspector to help.
  • edited January 2018
    Wops, sorry about not posting, for some reason your message wasn't loaded :(
    The anim engine is custom,
    image
    Debug log of the "GetMoveSpeed()" function isn't reaching infinity anymore.
    Would it be possible to parse the moveSpeed to Unity units?

  • edited January 2018
    Sorry, I meant the full Inspector - as in all the components on the root object.  Specifically, I'm also looking to see where your Animator component is.

    Are you using the latest release?  Also, what is your Destination accuracy slider value set to in the Settings Manager?
  • There isn't any Animator component since I'm using Spine and various skeletons and I change the skeleton and it's animation depending where the character is facing.
    Destination accuracy value is 1 (max).
    I can't post the full inspector at the moment since I won't be able to check our project until this friday.
    Thanks for your patience and help.

  • OK, and have you also enabled "Super-accurate" mode, which appears when the accuracy is set to 1?
  • Attempt to be super-acurate is checked.
    Pathfinding update time is set to 0.

  • The "super-accurate" mode will complicate things since it basically lerps the character to their exact destination regardless of direction, which may be the cause of some of the strange values.  I'd recommend disabling it for the moment.

    With the latest release, there is actually a new "Retro-mode" movement option in character components which provides pixel-perfect movement without the need for "super-accurate" mode.  You may find that it is useful for your needs, so I'd recommend trying it out if you haven't already.  More on this option can be found in the "Retro movement" chapter of the Manual.

    Otherwise, the literal per-frame speed should be equal to the "newVel" float that's updated in Char.cs' MoveUpdate method.  Find the line:

    transform.position += (newVel * _deltaTime);

    and place in a Debug.Log:

    if (this is Player) Debug.Log ("Frame speed: " + newVel);

    Does that give more accurate values?
  • Thank you so much Chris

    I can't test the "Retro-mode" since we are maintaining the AC version but the "newVel" Variable gives a big value, but it needed to be multiplied by Time.deltaTime.

    Problem solved, thanks for your patience.

    Have a good day :)
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.