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 RealLifeSpartan · Jan 11, 2014 at 09:02 PM · collisioncollidertriggerlightshadow

Using shadows as Triggers?

Hi,

At the moment I am working on a new game of mine, with the overall idea in a nutshell being that you have to stay in the shadows and not get caught. Almost all of the game is complete, minus the crucial part, being that when you step out of the shadows in to the light you are caught. Is there any possible way (through scripting) that you can have the shadows/light acting as some form of 'Trigger' or is the only solution the long winded process of placing individual colliders everywhere?

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 tomekkie2 · Jan 11, 2014 at 09:11 PM 0
Share

Cast a ray from the light source to the centre of the object or to its renderers.bounds corners, can you? The shadow casters should have their colliders enabled.

avatar image RealLifeSpartan · Jan 12, 2014 at 08:40 PM 0
Share

Firstly, thanks for the quick reply. The idea suggested sounds like it should work and I'll get started to try and figure it out. I'll let you know how I get on. Again thanks for the answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pangamini · Jan 14, 2014 at 07:40 PM

I first thought about light probes, but you probably want to have dynamic lights and having only certain points raycast checked may fail (what if corners of AABB are in the shadow, but really just corners?) And then i got this idea: to use rendering to detect light in the area. I won't give you an exact solution, but i don't see a reason why this shouldn't work. So:

Create a camera with black background. This camera will be set to filter everything but an object you will use as a light sensor. Could be cube or capsule of a player size, or the player object itself. But rendered with a special shader, that renders both front and backfaces, with additive blending (and lighting enabled)

This camera will look at the sensor object from closeup (so it takes most of the "screen") render into a texture (very small resolution is enough). The camera will also do a very strong blur on the postprocessing, so strong so the whole texture gets almost average color.

Then, simply get the renderTexture and get pixels out of it (since the color is almost average everywhere, only one or few, spread across its surface, will be enough). Average these colors and you will get some data about how much your character is lit.

Another modification would be to render the light sensor with special lighting shader (no surface shaders for lighting) so that you would calculate detection threshold per pixel, and make the pixels either completely white or black. In this case, the pixels you pick from the texture would have to be anything above zero and you'd safely say the sensor was lit over the threshold intensity somewhere.

This type of detection would work mesh-wise.

Again, i've never tested anything like this.

Comment
Add comment · Show 1 · 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 RealLifeSpartan · Jan 25, 2014 at 02:54 PM 0
Share

Thanks for that answer. It seems very in depth, I gave it a go and could not get it to work. Since then I have changed the overall concept of the game (through different reasons, not giving up!) and therefore will not be needing this anymore. Once again thanks for your help

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble with light switch 3 Answers

Colliding two GameObjects 1 Answer

OnTriggerEnter is not running! Need help with collision. 2 Answers

Trigger Spawning? 1 Answer

Can't click gameobject when over another trigger? 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