Search Unity

Is there a function or method to calculate the velocity being applied to an object?

Discussion in 'Physics' started by dusthound, Dec 26, 2018.

  1. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    Is there some kind of method/function that can be used to get the current velocity that is being applied to an object? I am asking this because I am working on a game and need to know the current velocity the player is moving at in order to improve the controls.
     
  2. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    thanks. I seem to get a lot of help from you, thanks a lot.
     
    Lurking-Ninja likes this.
  3. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    I looked at that and it just showed a way to add velocity to an object instead of using AddForce. Do you know if this can be used to set a variable equal to the velocity being applied to an object?
     
  4. Code (CSharp):
    1.     void FixedUpdate()
    2.     {
    3.         Debug.Log(GetComponent<Rigidbody>().velocity);
    4.     }
    5.  
    Object with Rigidbody in an empty scene:
    velocity.PNG
     
  5. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98