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
1
Question by BerggreenDK · Oct 18, 2012 at 08:24 PM · touchtransparencydragpixelcollisiondetection

Detect touch on a 2D plane with a transparent image?

I am trying to make a simple jigsaw puzzle where the player can touch and drag a piece. But when the pieces gets close, I need to make sure I detect WHICH piece is touched as they are concave figures.

So a simple boxed approach wont fit once they get dragged near each other.

I was thinking of some sort of masking approach like we used to do back in Flash/C++ days.

Just wondering what great functions we might have available for same thing in Unity?

Any samples/suggestions are welcome. I am trying to figure out if GetPixels is an option or if I should calculate a masking layer from the tranparacy in the PNG or if I can detect the alpha directly and then go through the depth/stacks of objects if the pixel you touch are transparent.

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 AlucardJay · Oct 18, 2012 at 10:11 PM 0
Share

Very interesting. I would use just a box collider, with the size set to approximately 1/3 of the jigsaw piece and centered. Then hopefully none of the box colliders will overlap, but the pieces can only be selected from the center. Or align the box collider on the piece where you think a player would intuitively press/touch to select the piece. This is just a suggestion (and not what you want!), so good luck, and I am upvoting this question =]

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Oct 18, 2012 at 11:07 PM

You can use GetPixel and read out the alpha. You'll need to make sure the texture (import) settings allow read/write (even if you are only reading it). If there is only one material on your mesh, no problem. If it is a multi-material (has submeshes), it's a pain to track down which submesh is hit, hence its material. Hope you don't need that.

If you are using rectangular (or not very high-detail) meshes, they will interpenetrate each other. So your raycast should be of the variety that gives you the list of objects hit, not just the nearest one. Using the hit point info from the raycast hit, read the pixel at that location, check alpha. If transparent, try next hit on the list, otherwise you found it.

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

11 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

Related Questions

Help With Touch to Drag Script 1 Answer

Object sometimes stops after drag, instead of sliding? 1 Answer

Touch deltaPosition Android 1 Answer

How to drag object along with dragging touch? 1 Answer

Finger gesture works/fails on different devices? 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