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 TheFrankman123 · Oct 14, 2011 at 02:23 PM · collisionraycastspotlight

Collision Detection on Spotlight

Hello, I am creating an enemy that is holding a flash light. I only want the enemy to persue if they are in the light of the flash light. What do you think is the best way to do this? I thought of having a raycast coming off the enemy so that if they made contact with the raycast the enemy would persue. However this has issues because raycasts can go through walls and i don't want the enemy to be able to see through walls. I would also just but a collision detector on the spot light itself which i am having eminate from the flash light, however the size of my spot light is different obviously to the size of light that it puts on the ground so it wouldn't be accurate either.

Suggestions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by syclamoth · Oct 14, 2011 at 02:44 PM

Well, to begin with raycasts only go through walls if you specifically tell them to, so that isn't really a problem.

What you need to do here, is remember that the 'spotlight' is not actually the thing that allows the enemies to see you- it is, in fact, a signal to the player that they will be visible if it passes over them. With this in mind, just forget all about the light for a moment and treat it just like a standard "view cone" problem. There are a few ways of managing this problem- you could draw a line between the player and the enemy, and detect both whether the player is in view, and whether the line is at the correct angle from the direction the enemy is looking in.

One rather nice solution to this problem that I have seen, is to fire off one (or more) random raycast every fixed update, from the enemy's eye point to a random position on your player's model. That way, with a combination of 'view cone' and occlusion testing, you can get a fairly realistic idea of how visible your character is to the enemies.

Lastly, when you have all of that working, you should put the spotlight back on, in such a way that it always reflects the AI raycasting- so that the player always knows where the enemy is looking.

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

Answer by TheFrankman123 · Oct 14, 2011 at 03:18 PM

Thank you, a lot to think about there!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Surface with hole and Raycast - Which collider 1 Answer

How to do a raycast to make my player unable to move through certain objects? 2 Answers

How do you raycast from an object ignoring only that object? 0 Answers

Detect if ball is on a platform or if it fell 4 Answers

Play Audio-Clip On Ray Casting Collision 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