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 Vel_1828 · Jul 14, 2014 at 06:10 PM · camerashaderoutlinevisible

Render if Object is behind obstacle?

Simply put: The Pink-Arrow Effect from GTA2 - Picture below, under the tags.

[1]: /storage/temp/29201-1.jpg

In words: When Object becomes obstructed (is behind obstacle), render a Sprite over it (here - the Pink Arrow).

I found the "isVisible" command with all of it's options, but it only works when something is "in the range" of the Camera View - not checking if it's behind obstacle or not.

There are some Shaders which can be seen through walls and they are working fine (Silhouette Diffuse, for example). But I found no way to turn them off when the Character "is" seen (so the Arrow is "always" on the character's head, even without obstacles in way).

And worst of all - it is needed to be used on the Enemies, so they have an indicator (a similar arrow, just red) of where they are, when they stand behind cover.

Help...?

1.jpg (50.6 kB)
Comment
Add comment · Show 3
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 robertbu · Jul 14, 2014 at 06:54 PM 1
Share

You can raycast Physics.Raycast() or Physics.LineCast() between the character and the camera. The more cast you do, the more accurate your detection will be. For 2D, raycasting from the four corners and the center of the character will be pretty accurate. For 3D, the center and the eight corners of the bounding box will be pretty accurate. Note you likely don't have to do this every frame. 5 or 10 times per second is likely enough. If you use Linecast between the character and the camera, any failure to find an object will indicate the camera can see the character.

avatar image Vel_1828 · Jul 14, 2014 at 07:02 PM 0
Share

I'll try this option, but with, for example, 30-50 enemies on screen this could be problematic. It'll be my emergency plan - more ideas are still welcome. :)

avatar image robertbu · Jul 14, 2014 at 07:39 PM 1
Share

I don't know your game, but I'm guessing that much of the time either 1) the enemy will not be visible to the camera (isVisible is false so you don't have to raycast), or 2) a raycast from the center of the enemy will find the camera (i.e. the first raycast from an enemy will find indicate the enemy is visible). If my guesses are true, combined with a less frequent check than every frame, the raycast load will be acceptably low. Back of the envelope calcualtipn with these assumptions: given that you want to check all your enemies five times per second, and a frame rate of 60 fps, you end up with a Raycast load of about 5 raycasts a frame.

1 Reply

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

Answer by Vel_1828 · Jul 16, 2014 at 01:53 PM

Robertbu was right - using a simple Yield WaitForSeconds coroutine (random float # seconds between 0.4 and 0.5) still makes it CPU-friendly and still everything works well. Thanks a lot! :)

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

2 People are following this question.

avatar image avatar image

Related Questions

Constant width of outline shader 0 Answers

CommandBuffer's CameraEvent ordering not in sync with shader rendering queue? 1 Answer

Parse Error on OutlinedDiffuse Shader 0 Answers

Changing shaders in a game during runtime 1 Answer

Know if gameObject is being seen 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