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 Kensey_Quarantine · Mar 24, 2015 at 02:31 PM · collisionraycastdetectionflashlight

Enemy got lit by flashlight detection

Hi there, so im developing some 3d horror game and i need to check if enemy got lit by player's flashlight. Raycasting from camera.transform.forward isnt a solution cause it dont full represent flashlight's light cone form. Any ideas?

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 CHPedersen · Mar 24, 2015 at 03:21 PM 1
Share

A flashlight's area of effect is a cone, so if you wanna know if an object gets hit by it, you're basically asking if the object is inside or outside of the flashlight's cone.

There's code to check this here:

http://stackoverflow.com/questions/10768142/verify-if-point-is-inside-a-cone-in-3d-space

It requires you to deter$$anonymous$$e some input point, however. $$anonymous$$aybe do it once for each of the corners of the enemy's bounding box?

Alternatively, you could raycast a number of times with the flashlight as the origin and aimed in uniformly distributed places around the area of the cone's circular bottom. The number of times can be considered a 'sample density' and should depend on the enemy's size such that enough rays are cast that the enemy can't possibly get missed, if inside. If the flashlight has a sufficiently narrow area of light, or sufficiently short range, it might not have to be that expensive.

avatar image Kensey_Quarantine · Mar 24, 2015 at 07:40 PM 0
Share

Oh thanks! The second method is really a solution. Just need to add musltiple raycasts on different angles... still, i think i can handle it.

By the way, first method is not for situation like this — a wall between player and enemy would still trigger the collision. Thanks for suggestion anyway mate!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessespike · Mar 24, 2015 at 03:02 PM

Have you tried a SphereCast? I know it's not a cone. But it might be close enough for what you're trying to simulate.

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 Kensey_Quarantine · Mar 24, 2015 at 07:45 PM 0
Share

Thanks, but thats not what am i looking for. Sperecast would not collide enemy in weird ways — just like a situation when enemy is behind a thin pillar. In that situation enemy would be visually lit, but the event would not trigger.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple/Different footsteps sounds (solved) 2 Answers

How can I make it so that my player only moves if there is no wall in the direction he wishes to move? 1 Answer

Create interchanging Raycast cone for flashlight 2 Answers

Capturing a point 2 Answers

Detect if ball is on a platform or if it fell 4 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