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
1
Question by AntzyP · Mar 28, 2016 at 12:44 AM · transparent shadersee-through

Make object visible through selected objects only

I have an object, such as a gun, inside a cylindrical enclosure. The player can move around but since gun is inside cylinder, he can't see it. Upon activating a power, he gets something like X-Ray vision and can see the gun through the cylinder. This much I have been able to achieve using another camera with higher Depth, Culling Mask set to only the gun's layer and Clear Flags set to Depth Only.

Now I want that the object should be visible ONLY through the cylinder. Right now it shows on top of everything. If he has a wall or any other object in between him and the cylinder, the gun should not be visible. I cannot set the cylinder to transparent as the cylinder has its own texture and is opaque(wall and objects behind the cylinder shouldn't be visible through it) and the gun should have 100% opaqueness and visibility(so no partial transparency). I'm unable to find a way to do this. Don't mind using shaders if it's possible through them...

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 AntzyP · Mar 30, 2016 at 12:19 PM 0
Share

Bump! Anyone who can help me out here?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by RoofTurkey · Mar 30, 2016 at 12:50 PM

Probably you can raycast from the player (camera) to the gun and check if it hits a cylinder, using a tag for the cylinder. If it does then enable the renderer on the gun, else don't.

This would look something like this:

 Vector3 dir = gun.transform.position - camera.transform.position;
 dir = dir.normalized;
 
 if (Physics.Raycast(camera.transform.position, dir, out hit)) 
 {
     if (hit.tag == "Cylinder")
     {
         gun.GetComponent<Renderer>().enabled = true;
     }
     else
     {
         gun.GetComponent<Renderer>().enabled = false;
     }
 }

For more info check: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html http://answers.unity3d.com/questions/697830/how-to-calculate-direction-between-2-objects.html

Comment
Add comment · Show 3 · 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 AntzyP · Mar 31, 2016 at 09:29 AM 0
Share

Thanks for your idea. Your method comes very close to what I want. But it only checks if the center of the object is in view and shows all of it if the center is visible and hides all of it if the center is out of view. For example, If it's a large or long object(like the gun in our case) an object could be obstructing 1/3rd of the object but since the center of the gun is visible, the 1/3 part behind the object will show through it. That will ruin the effect I'm going for.

avatar image RoofTurkey AntzyP · Mar 31, 2016 at 09:39 AM 0
Share

Good point. In that case I'd say you might wanna try putting all 'default' objects on one camera (that renders first/on top), then have the second 'gun' camera and finally have the 'transparant for guns' camera. That should give you the right effect, right? This way you should get the right effect on the objects in the third camera render and not on the other objects in the first camera render.

avatar image AntzyP RoofTurkey · Mar 31, 2016 at 09:58 AM 0
Share

That's it! Thanks for your help! I can't believe it was that simple... Next I'll try having depth order among the cylinders. That is, have multiple cylinders such that the one nearer hides the cylinder behind it along with its gun. I'm thinking that might require a separate camera for each cylinder and setting their depths at real time according to a depth test for cylinders. $$anonymous$$ight become very resource intensive.... Thanks again for your help. I'll mark it as the answer and hopefully someone in the same boat will read your comment to figure out the answer...

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

i cant see the objects 2 Answers

make gameobjects visible when behind other gameobjects 3 Answers

How to make my brown circle transparent so i can see the green ground? 0 Answers

Object see-through when rendering mode is set to Fade 1 Answer

Standard shader's Fade rendering mode won't allow full opacity with a textured material 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