Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by nathan · Dec 10, 2012 at 02:03 AM · center

How to get center of an object

Hi,

I want to use an cube(lets call "A") to move other objects(cube or capsule). Other objects will be moved when the object "A" is forwarding closely to these objects. Thus, i want to get the distance between "A" and other objects. So, i want to know the center coordination of an object? Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
53

Answer by bblhaugh · May 30, 2013 at 10:21 AM

If your models aren't centered. transform.renderer.bounds.center

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matt_NB · Oct 07, 2013 at 01:32 PM 0
Share

Brilliant general solution, would up-vote but not enough karma :P

avatar image Ziad · Oct 07, 2013 at 02:29 PM 0
Share

I'll up-vote it for you, $$anonymous$$att_NB.

avatar image jethrogillgren · Mar 15, 2018 at 05:37 PM 4
Share

Thanks. In 2017 this code is gone, ins$$anonymous$$d you can use

 GetComponent< Renderer>().bounds.center

avatar image unity_13macoates jethrogillgren · Oct 12, 2018 at 03:19 PM 0
Share

Thanks!!!!

avatar image marcospgp · Jan 07, 2021 at 12:56 AM 0
Share

Renderer can no longer be found in Transform. GetComponent<> has to be used, as pointed out above!

avatar image
2

Answer by Eric5h5 · Dec 10, 2012 at 02:09 AM

transform.position. The only way that wouldn't be the center is if you use off-center models that were not modeled around the origin.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathan · Dec 10, 2012 at 11:07 PM 0
Share

Thanks, man

avatar image eneroth3 · Nov 02, 2018 at 04:57 PM 3
Share

It's perfectly valid not have model without the origin in center, e.g. a swing door with the origin on the rotation axis.

avatar image Deathdefy eneroth3 · Nov 02, 2018 at 07:37 PM 0
Share

agreed, this is very common.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Error with picking up an item... 1 Answer

Unity 3d C# GUI box goes off to the side needs to be in the center of the screen 0 Answers

center of object group 0 Answers

C# Physics.SphereCast Center of Screen 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges