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 castor · Nov 07, 2013 at 07:47 PM · collisionguioverlappingdialog

How to prevent GUI dialog windows from overlapping?

So here is my situation.

It's a top down game and when characters speak you see a dialog balloon over their heads. This dialog balloon follows the characters as they move around the environment.

Now what I want to prevent is the balloons from each character to overlap with each other.

If 2 characters are speaking and they get close to each other then the balloons would not overlap. Same if a third character gets closer and is also talking, his balloon would stop once it touches the other character's balloons.

I'm using unity GUI for these and depending on what they are saying the balloons change in height and width.

I managed to get something working for one character where his balloon is able to dodge other character balloons BUT if I apply the same code to the other character balloons they keep dodging each other.

This is what I kind of have in mind:

  • Have a List/Dictionary containing all the occupied spaces (Rect)

  • Current rectangle checks against the list to see if its intersecting with any rectangle in the list.(isOverlapping)

  • If isOverlapping, move in the opposite direction of current movement (horizontally and vertically) until !isOverlapping

Is there a simpler way to do this? Am I even thinking correctly?

  • UPDATE **

So I got it to work but slightly changed the way I'm doing it :

  • Have a list with all the rects

  • Each rectangle checks against all the others. The moment it finds a overlap it tries to fix it (and stops checking for other overlaps).

  • Once its no longer overlaping it tries to go back to orig position and look for overlaps again.

It works pretty well. I also used aSmoothDamp so the rect don't jerk around when trying to get back to the position. But you are right, it feels a bit messy, I think probably fixing it in the core design would be better.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RyanZimmerman87 · Nov 08, 2013 at 08:45 PM

This can be a bit tricky ideally you would just have the game set up so the text bubbles would never overlap to begin with with timers character spacing etc.

I also recently set up text bubbles and I'm using the characters position in relation to the camera to determine the position of the text bubble. So there's really no nice and easy way to have them not overlap since they can constantly move around and I have several camera angles.

I'm not sure the whole problem seems a bit messy to me and I'm almost thinking I'll just try to design it so that sort of thing won't be likely to happen in the first place with bubble timers, spacing out the characters a little bit etc.

You might be able to just use GUI.depth to display the boxes in the order of priority or by the time they first appeared they update some kind of public static int that assigns the GUI.depth of that box.

That's probably what I'll do at this point if I try to improve it. I think your plan you listed could work really well potentially. Just seems like too much work for me on my project at the moment to attempt something like that, I got a lot of high priority things I need to start at the moment.

Hopefully someone can give you a more useful answer or you can figure it out and post your solution to help myself and others.

At this point I think it's just gonna be by design that this could happen occasionally but it should be rare if we set up the scenes right.

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

16 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

Related Questions

how to create topology based reticle 0 Answers

Score count increase on hit 2 Answers

Editor Input Dialog 2 Answers

"Collision" between UI images 1 Answer

GUI.label overlapping text 1 Answer


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