Reply To: Unity Space shooter…How do I get a Rigid Body Velocity Component?

Forum Archive Unity Space shooter…How do I get a Rigid Body Velocity Component? Reply To: Unity Space shooter…How do I get a Rigid Body Velocity Component?

#31831
Jonathan Gonzalez
Participant

    I replied to your other message directly, but I’ll post it here as well so others can see it:

    in order to use the Rigidbody class you need to use GetComponent in Start or Awake. In the script they provide they access it directly since that was possible before Unity 5. So in the movement script add a variable for the rigidbody then add a Start method and add GetComponent like this:

    public Rigidbody rigid;
    void Start ()
    {

    rigid = GetComponent<Rigidbody>();
    }

    Assuming this script gets applied to the object that has a Rigidbody component. If it doesn’t then you can manually assign it but you must specify where this component is located in your script as such:

    rigid =rigid.GetComponent<Rigidbody>();