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 neverletmecareagain · May 09, 2014 at 05:05 PM · positioncoliderproximity

Getting position of specific collider2D

Hello, I have a huge problem getting one thing to work (I'm not a programmer so I'm struggling a lot with basics often).

First of all here's an image that may help in understanding me. https://www.dropbox.com/s/799ihskfji1sjmd/unityquestion.jpg

Now, I want a game to tell how close is Player to a collider2D (Mesh or Box, I assumed Box will be easier). Earlier I had it solved by adding a trigger sphere collider on a Player and it returned a message when hitting the other collider. Worked perfectly fine but now I want to differantiate messages according to collider relative position to player (above, below, left and right) I tried to do separate colliders for every possibility and give them different tags, what I assume would work but it creates new problem - if the walls are thin then the sphere collider on a player will recognize both above and below or left and right colliders. Therefore I've tried to create if instruction that checks 1. if the collider tag is "above" and 2. if the Y of this collider is less then players Y (more if below and so on). And I don't know how to ask for position of the collider my sphere is colliding with at the very moment. I don't want to add different tags for all the colliders as there can be a lot of them in one scene.

So, if there's an easy solution to my problem I would be really greatful as I cannot sleep without it being solved ;)

Cheers

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 Jeff-Kesselman · May 09, 2014 at 05:49 PM

Get the vector between the two colliding objects and check its quadrant.

 Vector3 vecToCollision = collision.transfrom.position - transform.position;
 
 if (vectToCollision.X<0) {
     if (vecToCollision.Y<0)) {
        //top left quad
     } else {
        //bottom left quad
     }
 } else {
     if (vecToCollision.Y<0)) {
        //top right quad
     } else {
        //bottom right quad
     }
 
 }
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 neverletmecareagain · May 13, 2014 at 10:07 AM 0
Share

hey, thank you for your answer unfortunately I'm using trigger, not collision, nevertheless I've solved this problem already by comparing x's and y's of the collider with x's and y's of the the object :) Cheers

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

Camera rotation around player while following. 6 Answers

My Position suddenly changes 0 Answers

Trouble converting transform.position to C# 1 Answer

Adding a position offset to a force towards an object 1 Answer

Camera position not updating 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