- Home /
Light Colision
Hi! I'm still learning Unity, and in my work, I intend to simulate some kind of sensor light.
The idea is to have an area or spot where the light is directed, and I want to register the ammout of time a passing object stays under the light.
Do you have any suggestions or ideas for the best way to pull it off?
Thanks in advance!
Answer by Kiloblargh · May 24, 2012 at 01:00 PM
Model a rough cone (like 16 polys) that matches the light angle (I'm assuming this is a sweeping spotlight, not a stationary floodlight, or the solution would be trivial) with its origin at the point, make it a mesh collider trigger, parent to the light object, then check when the object enters the trigger and when it exits.
Hmm, the light I want to use is static and it's supposed to be like a laser beam, so do you think if I add a capsule collider to the light I can have it detecting the colisions?
The passing object is a rigidbody with a boxcollider.
I would use a ray cast if it is a lazer. cast the ray from the source light position to the target. I've had good results with that. go to the Unity docs and look into raycast. $$anonymous$$y advice with this would be to do the actual cast (which you will not be able to see) and for testing purposes also do a Debug.DrawRay which will show up in the editor. It's easy to set up, but also easy to make a mistake with. It's also a less CPU intensive solution for what you want to complete.
Your answer
Follow this Question
Related Questions
Time release Collectable 1 Answer
How can I make it so that inputs only function once per second? 2 Answers
Light rarely turns on 1 Answer
Changing light intensity over time via mathf.lerp 2 Answers
Using shadows as Triggers? 1 Answer