Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Moving Kinematic Rigidbody2D velocity

Discussion in 'Physics' started by eses, Jun 27, 2015.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi,

    like the topic says, seems like I'm unable to get velocity of moving Rigidbody2D that is set as kinematic, animated by either Animator or Script that moves object in FixedUpdate.

    Someobject.GetComponent<Rigidbody2D>().velocity only returns Vector2 value that is zero.

    Should I even be doing this? Or should I just calculate velocity from previous and current position. I think I've seen some tutorial where velocity was used, however can't find any answers using search engines.

    Info: I'd use this velocity to modify object's velocity on platform and such.

    Any help appreciated!
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I dont think kinematic rigidbodies can have velocities.
     
  3. Osirius

    Osirius

    Joined:
    Oct 10, 2014
    Posts:
    47
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Thanks guys - I went to bed and couldn't answer, but I already got this fixed.

    HiddenMonk: I don't know what I had wrong initially using rb.velocity , but setting rb.velocity seems to actually be working, doesn't matter if set as kinematic or not.

    Now, by setting velocity I still see the velocity of object and can use that.

    Osirius: I found that same message, that's why I mentioned calculating velocity - I'd rather use animation to move object, as ramping speed up/down when stopping becomes too complicated - I've got no direct answer how to do this. With animation it's easy to control.