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 casualbanana · Apr 16, 2014 at 03:26 PM · collisionflashlightspherecast

Using a "Flashlight" as a form of Detection

Hello Unity Community,

I have been working with Unity for a little while, and have ran into a problem. I want to make a quick example of a "stealth", the basis of the game is that the enemies can only detect you if you are in their flashlight sight. After researching I found out that Sphere casting would be the best way to do this. However, I found none of the documentation helpful, and after looking at other examples I am still stumped on how to "detect" of the block is in the flashlight area.

Any help is greatly appreciated!

alt text

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 komodor · Apr 16, 2014 at 03:34 PM 1
Share

i've done it with 2 spherecasts - first defines range second the cone as it has center on the border of the first sphere at the position in the center of the view

avatar image robertbu · Apr 16, 2014 at 03:38 PM 0
Share

@komodor - I take back what I said about Spherecast(). This should work.

avatar image deltamish · Apr 16, 2014 at 03:44 PM 0
Share

hi sorry to point same thing out but can't you use raycast and use FOV caluclation to do that it is much more efficient and easier too

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by casualbanana · Apr 16, 2014 at 03:54 PM

I just figured it out actually, thanks anyways for the comments (well I actually stole concepts and pieces of code from other places). If anyone has an easier more robust way I would be glad to hear it!

 public var radius = 1.0f;
 public var distance = 10.0f;
     
 function Start () {
 
 }
 
 function Update () {
 
         var forwardRay = new Ray(transform.position, transform.forward);
         var hits = Physics.SphereCastAll(forwardRay, radius, distance);
     
         Debug.DrawRay(forwardRay.origin, forwardRay.direction * distance, Color.white);    
         for (var hit in hits)
         {
             Debug.DrawLine(forwardRay.origin, hit.point, Color.red);
             Debug.DrawRay(hit.point, hit.normal, Color.blue);
             
             if (hit.collider.tag == "Player")
                 print("player detected");
         }
 }
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

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

Related Questions

How do I get all colliders within a radius at a given point? 1 Answer

Lay a Sphere on a Point 3 Answers

Why is my spherecast returning an incorrect hit on mesh collider? 1 Answer

Spherecast/linecast in 2.5D (line of sight checks) 1 Answer

SphereCastAll return individual surface normals 0 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