Search Unity

Get center of gameobject

Discussion in 'Scripting' started by JamesLeeNZ, Feb 26, 2012.

  1. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Is there any correct way to do this.

    rigidbody.worldCenterOfMass is close, but slightly off.

    I dont want to create an empty gameObject and align the transforms.
     
  2. unknows

    unknows

    Joined:
    Sep 5, 2010
    Posts:
    51
    if i'm right. please correct me if i'm wrong...
    Code (csharp):
    1. Transform.position
    this is the center os your gameObject.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, that's just the position. Try renderer.bounds.center.

    --Eric
     
  4. unknows

    unknows

    Joined:
    Sep 5, 2010
    Posts:
    51
    Thank you.
    Regards.
     
  5. lalamax3d

    lalamax3d

    Joined:
    Aug 23, 2012
    Posts:
    17
    thank you sir.
     
  6. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60