Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Bombshell93 · Aug 02, 2012 at 09:09 AM · shooterwallstop-downgradientsee through

Top-Down Shooter, see through walls?

I'm making a top down shooter, nothing too fancy, but I face a problem when the player goes under a bridge or a tunnel, which is the player can't see themselves or anything around them.

The bridges and or tunnels will be traversable over and under (under obviously being the problem) Is there any way I could get a gradient circle controlling the alpha of all that's drawn above the player?

Any and all help is greatly appreciated, Thanks in advanced, Bombshell

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

2 Replies

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

Answer by $$anonymous$$ · Aug 05, 2012 at 10:44 PM

I would approach this problem like this. Have a ray casting from camera to the player. Check if something gets hit from that ray cast. If it does check if its the Bridge. If it is the bridge, then make it transparent.

So for this to work, you have to create a material and set its shader to be Transparent/Diffuse, and assign it to the bridge. And attach the following script to Bridge as well.

 using UnityEngine;
 using System.Collections;
 
 public class Bridge : MonoBehaviour 
 {
  public Color transparentColor;
  private Color m_InitialColor;
  
  void Start () 
  {
  m_InitialColor = renderer.material.color;
  }
  
  public void SetTransparent()
  {
  renderer.material.color = transparentColor;
  }
  
  public void SetToNormal()
  {
  renderer.material.color = m_InitialColor;
  }
 }

After doing that create a new GameObject and add the following script to it. Oh and drag and drop the Player transform to 'playerTrans' property on the inspector as well...

 using UnityEngine;
 using System.Collections;
 
 public class ObstructionDetector : MonoBehaviour 
 {
  public Transform playerTrans;
  private Bridge m_LastBridge;
  
  void Start () 
  {
  StartCoroutine(DetectPlayerObstructions());
  }
  
  IEnumerator DetectPlayerObstructions()
  {
  while(true)
  {
  yield return new WaitForSeconds(0.5f);
  
  Vector3 direction = (playerTrans.position - Camera.mainCamera.transform.position).normalized;
  RaycastHit rayCastHit;
  
  if(Physics.Raycast(Camera.mainCamera.transform.position, direction, out rayCastHit, Mathf.Infinity))
  {
  Bridge bridge = rayCastHit.collider.gameObject.GetComponent<Bridge>();
  if(bridge)
  {
  bridge.SetTransparent();
  m_LastBridge = bridge;
  }
  else 
  {
  if(m_LastBridge)
  {
  m_LastBridge.SetToNormal();
  m_LastBridge = null;
  }
  }
  }
  
  }
  }
 }

I've made a small video tutorial to show how this is done.

http://www.youtube.com/watch?v=dTY5_HRfICo

Comment
Add comment · Show 4 · 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 Bombshell93 · Aug 05, 2012 at 10:58 PM 0
Share

although I will not be using your technique I'd like to thank you for an idea, I'll write a shader to draw the world objects that takes in the players Projected Z and then compares it to the world objects projected Z, if its in the way a black and white image will be sampled for the alpha which will basicly be a blurred circle. This will make a peep hole effect when moving under things.

avatar image $$anonymous$$ · Aug 05, 2012 at 11:04 PM 0
Share

That sound like a very elegant solution. When you manage to implement it, if you could share a project file with us it would be great. But yeah, nice solution...

avatar image Bombshell93 · Aug 06, 2012 at 02:34 AM 0
Share

here you go http://pastebin.com/5mY$$anonymous$$hp4h you'll need to change the height check for anything other than a top down shooter, also because of how unity treats transparent objects you must split all objects effected by this if their going to noticabley overlap. EDIT: Actually I just realised you can not have overlapping objects, transparency has no Z-buffer in unity and so a lot of flattening occurs.

avatar image RedDjinnPro Bombshell93 · Aug 05, 2016 at 05:47 PM 0
Share

would this script youve linked to here be used as a component attached to the main camera?

Thank you!!

avatar image
0

Answer by toorican · Nov 14, 2021 at 11:41 AM

Hi If your still looking for a solution check our Asset as this is custom made shader for this use case. It can handle multi user multi buildings ( obstructions ) and is available for Standard URP and HDRP .

https://forum.unity.com/threads/rel...isible-within-buildings-std-urp-hdrp.1182130/ https://assetstore.unity.com/packages/vfx/shaders/see-through-shader-193955

Greetings Toorican alt text


sts-172-splash.jpg (217.9 kB)
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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Top Down shooter Moving while Shooting 0 Answers

Shooting a projectile with Unet 0 Answers

Instantiate gameobject on random position on 1. a graph and 2. another gameobject 0 Answers

How can I make walls with Collider2D components for a top-down game in Unity 2018? 1 Answer

Scrolling space shooter - making enemies drop currency 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