Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 yaezah · May 15, 2017 at 02:48 AM · uigameobjectpositionvector3centering

Trying to get a game object to spawn right above another game object instead of the point where the collider hit.

I'm using a box collider attached to my player's head to check if there are any items on the ground when he's looking down and instantiate a tooltip with the item's name, stats etc.

So I have everything pretty much working except for the fact that when he looks at a game object on the ground the tooltip instantiates at the exact point where the collider hit, and for larger items this is an issue because the tooltip instantiates halfway inside the item and is unable to be read.

So what I'm trying to get is whenever that box collider hits it instantiates the position of the tooltip right above the item and (optional) slowly follows my players head if he starts looking left or right until the collider isn't hitting it the item anymore

Here's what I have so far:

     void OnTriggerEnter(Collider other) {
         
 
         if (other.gameObject.tag == "Item") {
             GameObject item = other.gameObject;
             Vector3 itemvec = item.GetComponent<Renderer>().bounds.center;
             //Vector3 itemvec = new Vector3 (item.transform.position.x, item.transform.position.y + 0.5f, item.transform.position.z);
             if (infoBox != null) {
                 return;
             
             }
             else {
                 infoBox = (GameObject) Instantiate (uiWindow, itemvec, cam.transform.rotation);
 
                 //infoBox.transform.LookAt (cam.transform.position);
                 //infoBox.transform.LookAt (other.gameObject.transform);
             }
 
         }

 void OnTriggerExit (Collider other) {
 
     Destroy (infoBox);
 
 }
             

(You could tell above I tried uses render.bounds.center but it wasn't working)

Comment
Add comment · Show 1
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 yaezah · May 15, 2017 at 02:59 AM 0
Share

By the way I'm not using raycast because I'm trying to get a sort of cone effect from the players vision and instantiate tooltips for any items the box collider sees in front of him :) (and I'm still a noob and raycasts kind of confuse me)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · May 15, 2017 at 04:21 AM

I know you don't like it but raycast it is an obvios soulution to your problem. Alternatively you could make empty gameobjects parented inside your models to represent positions above the models for reference. then look for them on collisions. empty position markers are handy sometimes.

anyways here is the raycast:

 if (other.gameObject.tag == "Item") {
             Vector3 itemvec;
             GameObject item = other.gameObject;
             RaycastHit rch;
             Vector3 v;
             v=new Vector3(item.transform.position.x,100,item.transform.position.z);
             if(Physics.Raycast(v,-Vector3.up,out rch)){
                 itemvec=rch.point;
                 print(itemvec+" is top of your object's collider");
             }
         
         }
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

123 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 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 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 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 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 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

Finding position of a GameObject using its name? 1 Answer

how do i fix my script in the content below? 0 Answers

how to know position to gameobject's exist?! 1 Answer

How to keep the same position of the object instead of camera 0 Answers

Snapping to Object Forward Axis 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