Search Unity

How to get absolute speed of rigidbody attached to Rightcontrolleranchor

Discussion in 'Physics' started by pieter_oudenhoven, Jun 3, 2020.

  1. pieter_oudenhoven

    pieter_oudenhoven

    Joined:
    May 16, 2020
    Posts:
    2
    Hi,

    In my script I need the absolute speed of a 'paddle', which is a rigidbody attached to the Rightcontrolleranchor. The relevant part of my script is:

    public GameObject objectname;
    float velocitypaddle = objectname.GetComponent<Rigidbody>().velocity.magnitude;

    (objectname is then filled via the inspector with the paddle object)

    Now the problem:
    This works fine with any object I pick (for example a bouncing ball) except for the paddle object. When choosing this object, the velocity is always zero, even when I wave the controller like an idiot. Most likely the problem is caused because I checked for the paddle rigidbody:
    Constraints -> freeze position (x,y,z)

    This was needed to prevent the paddle from moving with respect to the Rightcontrolleranchor. So indeed, with respect to the Rightcontrolleranchor the speed is always zero, and it should be.

    But then how could I get the absolute speed of the paddle, so the speed with respect to the world?

    Thanks a lot for your help!
     
  2. pieter_oudenhoven

    pieter_oudenhoven

    Joined:
    May 16, 2020
    Posts:
    2
    Never mind, I already solved it by using the world coordinates to determine the speed.