Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get Velocity from player

Discussion in 'Physics' started by M_Keyla_M, Jan 12, 2021.

  1. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    Question,
    I'm trying to get an animation to play based on the speed/velocity of the player. I have used this method before with my NPC who has a Nav Mesh Agent. I used the "get velocity" of the Nav Mesh Agent to get the speed of that NPC to trigger the animation. My question is how i get the velocity from the player so i can start the animation? The screenshot is what i already have. Except for the "get velocity" part which keeps returning 0, 0, 0. That needs to be something else but i don't know what...
     

    Attached Files:

  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I've never used visual scripting, so I may be unhelpful.

    I assume the player is a rigidbody based on the image, how does the script/node know what body the player is?, it looks like it has some input connection.
     
  3. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Based on the image, i think you are doing the right thing, however, i'm not sure if you are changing the velocity at all. As a simple test, try to make your RB dynamic + use gravity, you should see how the velocity increases over time (and the animation changes/starts).
     
  4. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    the player has a rigid body yes
    The node checks “self” to see the rigid body, you can ofcourse also directly input the player into that slot but I tried that and nothing changed
     
  5. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    I’ll give that a try!
     
  6. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    How do i make it dynamic though?
    The "use gravity" box is checked
     
  7. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    A dynamic rigidbody is just a non-kinematic rigidbody (isKinematic = false).
     
  8. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    Oh well that was already the setup so i guess that wasn't the issue lol