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 stark89 · Sep 24, 2012 at 05:54 PM · collisiontexturecolor

Finding color of a body at the point of collision with another body?

Hi all,

I have a box collider attached to a body. Now whenever a ball comes in contact this body. I want to produce a particle effect that has the color of the point of contact on the box body. Note that am changing the texture of the box body at run time and the color I need should be based on the texture at the time of collision(ie the color of the texture, at the point of collision).

Thanks

Comment
Add comment · Show 2
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 Mander · Sep 24, 2012 at 06:13 PM 0
Share

take the RGB values of the main color of ur shader, compare and make a result color.

avatar image stark89 · Sep 24, 2012 at 06:17 PM 0
Share

Sorry but thats not wat i want, I need the color of the texture

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by hathol · Sep 24, 2012 at 06:23 PM

No code since I don't have Unity running, but an idea that should work:

1) Take a contact point _cp (collision.contacts returns a ContactPoint[] ... pick one)

2) Do a raycast from _cp.point+_cp.normal to _cp.point

3) The RaycastHit object gives you the object's renderer (and through that the Texture2D) and the UV coordinate (hit.textureCoord).

4) Now you can simply use texture.GetPixel(texCoord.x texture.width, texCoord.y texture.height) to get the color.

Hope this makes sense. For the raycasting part, you can have a look at that example: http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-textureCoord.html

Comment
Add comment · Show 2 · 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 stark89 · Sep 26, 2012 at 04:40 AM 0
Share

But does this work for box and sphere collider?

avatar image hathol · Sep 26, 2012 at 08:52 AM 0
Share

I don't see why not. The 2 problems I can see are: 1) if your colliders are too different from the actual object (not a problem if you're actually using a box and a sphere) 2) if there is something blocking the raycast. Put all your blocks on a separate layer and use the layer parameter in your raycast function and you should be fine.

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

Texturing/Coloring wherever you go 1 Answer

Texture and material not showing up 2 Answers

Adding bumpmap and texture color to my shader. 0 Answers

Ugly edges with multiple image parts in one texture 2 Answers

How do I fill a texture with one color? 2 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