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 mexicouger · Mar 08, 2014 at 05:35 AM · objectgetcoordinateat

How to get an object with exact coordinates?

Hello everyone, my first Question I'm posting. Basically what I'm trying to accomplish is getting an object(collider object) using the exact coordinates given. What I've been hoping and trying to accomplish is maybe I create a Ray right smack in the middle of the object I'm wanting to get, and see if I can get it that way but it doesn't seem to ever find it.

What I did earlier than that is create a ray using the given coordinates a bit down on the Y axis, and that works and all but is fairly glitchy and still not perfect.

So All I am wanting to do is just select an object at a specific location. If anyone has any ideas or needs further information let me know!

Thanks alot!

Comment
Add comment · Show 3
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 highpockets · Mar 08, 2014 at 05:55 AM 0
Share

I don't get exactly what you want to do.. It sounds like you already have the objects coordinates and you want to shoot a ray at it using those coordinates to "get it".

I'm thinking, what you want to accomplish, is to shoot a raycast out towards an object to manipulate it accordingly by means of clicking the mouse button on the object, am I right?

avatar image mexicouger · Mar 08, 2014 at 06:35 AM 0
Share

Basically I was trying to use a raycast to start in the middle of the object and end right inside the same object to be able to select it but the raycast, being inside the object, never registered it(And keep in $$anonymous$$d this was just one of the ways I figured I could select that exact object was using a raycast inside of it). However, after further prolonged searching I came upon my solution. Here is my block of code:

         Collider[] insideBlock = Physics.OverlapSphere(blockTestPos, 0.1f);
         int i = 0;
         for(i = 0; i < insideBlock.Length; i++)
         {
             if(insideBlock[i].gameObject.CompareTag("Block"))
             {
                 AudioSource.PlayClipAtPoint(placeObject, insideBlock[i].transform.position);
                 dusty = (ParticleSystem)Instantiate(dust, insideBlock[i].transform.position, insideBlock[i].transform.rotation);
                 DestroyObject(insideBlock[i].transform.gameObject);
             

Basically what it does is searches using a sphere with an actual radius(something I was trying to accomplish by just putting a raycast inside of the object) and grabs the object for use at the moment(In this case I grab it to destroy it)

avatar image highpockets · Mar 08, 2014 at 07:21 AM 0
Share

glad you figured it out

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Mar 08, 2014 at 06:48 AM

What you are asking is somewhat unclear, plus understanding why you want this calculation might lead to an alternate solution. With that said, you can use Physics.OverlapSphere() to get a list of any colliders that occupy the space at a specified position. The reference says it uses the collider bounds, but I believe from some testing that it is more accurate than that.

  var colliders = Physics.OverlapSphere(somePosition, 0.0);
  if (colliders.Length > 0) {
      Debug.Log("You found "+colliders.Length + " at that position and the name of the first one is "+colliders[0].name);
  }
 else {
     Debug.Log("No colliders found at that position");
 }

If you need to see if an object is at the exact position, you will need to cycle through the colliders returned by that function and check to see if the transform.position matches the precise position you are looking for.

Note that the Raycast approach fails because meshes are one sided. That means a raycast from inside an object will not hit that object.

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 mexicouger · Mar 08, 2014 at 07:19 AM 0
Share

Thanks alot for the response and I do apologize for the unclearness of my question. Luckily I worked out the conclusion on my own, and I narrowed it down to exactly what you put. I do again apologize for the vagueness of my question, I had a real hard time myself trying to summarize the problem from my head to paper.

I'm not going to bother trying to explain what I was trying to do because it seems primitive and inefficient after finding out about Physics.OverlapSphere haha. Anyways, good day everyone and thanks for the help!

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

21 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 avatar image avatar image

Related Questions

putting an object's x coordinate to another object 1 Answer

List all objects inside a group 1 Answer

How to get raycast and key click info. 1 Answer

Remove object based on its position alone 1 Answer

How do I set and get the position of a object? 3 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