Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Using GetComponent to get Velocity of another RigidBody...

Discussion in 'Scripting' started by Jason210, Apr 6, 2013.

  1. Jason210

    Jason210

    Joined:
    Oct 14, 2012
    Posts:
    127
    Stuck with this one. I need to know how to get the velocity of another rigidbody in the game....
     
  2. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    676
    Code (csharp):
    1.  
    2. //C#
    3.  
    4. Vector3 thatVelocity = someGameObject.GetComponent<Rigidbody>().velocity;
    5.  
    6. //unityscript
    7.  
    8. var thatVelocity : Vector3 = someGameObject.GetComponent(Rigidbody).velocity;
    9.  
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    You don't need GetComponent:

    Code (csharp):
    1. var velocity = otherObject.rigidbody.velocity; // C# and Unityscript
    --Eric
     
  4. Jason210

    Jason210

    Joined:
    Oct 14, 2012
    Posts:
    127
    Sorry, I missed your replies. Thanks. It was simpler than I thought!
     
unityunity