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
0
Question by Xav_m · May 17, 2011 at 05:45 PM · collidercenter

How to get center of collider in hierarchy

Hi, I want to find the Y position of 2 colliders in the following Hierarchy:

Player
--Colliders
---Collider1
---Collider2

So I have in a script attached to Player:

var c1:GameObject; var c2:GameObject; c1= GameObject.Find("Player/Colliders/Collider1"); c2= GameObject.Find("Player/Colliders/Collider2");

function Start () { Debug.Log ("C1: "+c1.transform.position.y); Debug.Log ("C2: "+c2.transform.position.y); }

Both of them are returning 5, what Do I need to get the correct centers?
Values are .3 and -.6

Thanks in advance.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Ashkan_gc · May 17, 2011 at 05:54 PM

you are getting the transform's position which is the position of the gameobject itself that can be different from the center of your collider.

you can get a reference to object's collider by writing:

c1.collider

but Collider class don't have position/dimention information of your collider so you need to know the type of your collider and get it using GetComponent, let's say it's a SphereCollider

c1.GetComponent(SphereCollider).center

is the center of the sphereCollider attached to c1. it's a value in object's local space (0.3) as you said and you should add transform.position to it if you want to have it in world space.

Comment
Add comment · Show 1 · 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 yoyo · May 17, 2011 at 06:37 PM 0
Share

Or use c1.collider.bounds.center -- this will work for any type of collider.

avatar image
0

Answer by Eric5h5 · May 17, 2011 at 05:48 PM

Are you looking for transform.localPosition? transform.position is world space.

Comment
Add comment · 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
0

Answer by Xav_m · May 17, 2011 at 10:14 PM

Thank you very much, used:

 c1.GetComponent(SphereCollider).center

and got what I needed. Regards.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Move sprite depending on its collider position 1 Answer

How would i find the center of an object with a Y axis offset to find the center on the top face? 1 Answer

How to Access GameObject.collider.cente in #pragma strict 1 Answer

FPS collider center offsets camera pivot? 0 Answers

How to get the center of a collider face and the halfExtents to the corners of that face? 0 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