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
2
Question by IMTRIGGERHAPPY9 · Oct 30, 2011 at 09:27 PM · gameobjecttransformvector3

Reverse Look up ( have transform want the gameObject of that transform)

so i have the vector 3 position of an object and i want to tell unity what object that is, is there any way to do this?

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
8
Best Answer

Answer by aldonaletto · Oct 30, 2011 at 11:03 PM

The title says one thing, the question says another. If you have the transform (like in the title), you can get its Game Object reference as transform.gameObject.
But if you have a 3D point (like in the question) and want the Game Object at that position, things are way different. You could do a Raycast passing through this position, but the ray should start at a near position, since raycasts do not detect objects from inside. The problem here is to choose a suitable near point: if the point is too near, it will be inside the object and nothing will be detected; if it's too far, other objects in between may be detected.
I think the best alternative is to define a point above enough the position - maybe 3 units higher - and do a raycast to the position:

var rayLength: float = 3;

function FindObjectAt(pos: Vector3): GameObject { var start = pos + rayLength * Vector3.up; // set a point rayLength above var hit: RaycastHit; if (Physics.Raycast(start, -Vector3.up, hit, rayLength)){ // do the ray down return hit.transform.gameObject; // return the object hit... } else { return null; // or null if none } }

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 IMTRIGGERHAPPY9 · Oct 31, 2011 at 12:26 AM 0
Share

thank you this worked

avatar image Bunny83 · Oct 31, 2011 at 04:18 AM 0
Share

I guess a simple Physics.OverlapSphere with a very small radius would do ;). You will get a list of all objects that intersect with that "point" so you can sort them out as you like.

avatar image syclamoth · Oct 31, 2011 at 04:47 AM 0
Share

How does that actually work? For example, if I'm using a collider which is completely bigger than the spherecast, will it still detect that collider? I'm almost certain that wouldn't work for non-convex mesh colliders...

avatar image
0

Answer by ninjarob · Oct 30, 2011 at 10:21 PM

No not realy because several objects can be in the same place so unity wouldn't know which to return.

if you have the transform of the object though you can do the following

 objTransform //contains the transform of the object


 var obj:GameObject = objTransform.gameObject
Comment
Add comment · Show 4 · 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 IMTRIGGERHAPPY9 · Oct 30, 2011 at 10:30 PM 0
Share

ok thank you

avatar image syclamoth · Oct 30, 2011 at 11:34 PM -1
Share

Or, in fact, you can use

 transform.gameObject.transform.collider.rigidbody.transform.gameObject;
avatar image syclamoth · Oct 30, 2011 at 11:35 PM 0
Share

(don't do it)

avatar image IMTRIGGERHAPPY9 · Oct 31, 2011 at 12:25 AM 0
Share

ha ha i am confused?

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

6 People are following this question.

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

Related Questions

Rotating a Vector3 in Instantiation 1 Answer

Finding the Current Vector of Travel 1 Answer

Instantiate GameObject towards player 0 Answers

Cannot conver UnityEngine.Transform to UnityEngine.GameObject 3 Answers

Difference between Vector3, Transform and GameObject 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