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
0
Question by nicholasjramsey · Feb 03, 2017 at 09:31 PM · line of sightfield of vision

Line of Sight - how to deal with partially visible objects?

I'm working on a mechanic that causes objects to interact when they're seen by the player's first person camera.

So far, I'm using a "LookReaction" script that goes on any object that will react to being looked at. It uses GeometryUtility.CalculateFrustumPlanes and GeometryUtility.TestPlanesAABB to check if the object intersects with the camera frustum. If it does, it uses Physics.Linecast from the camera to the object's position to tell if there's another collider in the way. If the Linecast returns the desired object's collider, the object counts as being looked at.

It works great, except for objects that are partially occluded by other objects. Since the line is cast to the center of the object, it doesn't count as being in line of sight if less than half is poking out from behind another object.

What's a good solution for catching objects that are mostly blocked from view? Thanks for any help!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Feb 03, 2017 at 10:03 PM

Why don't you have it test with a ray from the center of the screen rather than to the center of the object? That way it will trigger if the center of the screen is looking at the object and not blocked.

Comment
Add comment · Show 5 · 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 nicholasjramsey · Feb 03, 2017 at 11:56 PM 0
Share

Unfortunately this wouldn't work because I need the object to count as seen even if it's not centered on the screen.

avatar image FortisVenaliter nicholasjramsey · Feb 06, 2017 at 05:16 PM 0
Share

That's more difficult. You could try having multiple raycasts to various points, but that would be processor intensive. You could also render to a low-res alternate version of the screen where non-selectable objects are flat black and selectable are brightly colored. Then turn off anti-aliasing and check the produced image for the color of the object in question to deter$$anonymous$$e if it's on-screen.

avatar image elenzil FortisVenaliter · Feb 08, 2017 at 08:27 PM 1
Share

both of these are good ideas.

i wouldn't worry too much about the performance hit of multiple raycasts. if you're concerned, a simple test would be to take your current code and just repeat the raycast 100x or whatever and see how it goes. i would guess that 5 or 9 or so raycasts would be sufficient, but it all depends on the situation.

for the image approach, i think you'd set up a second camera and have it render to a texture. look up 'rendertexture'.

Show more comments

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

6 People are following this question.

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

Related Questions

[Line of Sight] Please evaluate my approach 1 Answer

Fog of War with Line of Sight comprehension 0 Answers

Destroy objects within ordered Array by line of sight 1 Answer

[2d Top Down Shooter] Duststorm and visiblity 0 Answers

Visually representing enemy cone of vision without Unity Pro? 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