Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by el-mas-pro-470 · Jan 23, 2019 at 11:48 PM · raycaststealthrealisticvisioncone

How do I make a cone of vision in raycast? Help!

Hello! I made a script from the vision of the enemy, the "field of vision" that actually worked !, the bad thing is that it is a line and it is very sub-realist, can I do the cone angle vision style? The most realistic enemy vision system. Thank you!!

 using UnityEngine;
 using System.Collections;
 
 public class EnemyVision : MonoBehaviour {
 
     public float Distance;
     public Transform SightObject;
     public bool Detected = false;
     public GameObject Enemy;
 
     void Start () 
     {
     
     }
     
     void Update () 
     {
         RaycastHit hit;
         
         if (Physics.Raycast(SightObject.transform.position, SightObject.transform.forward, out hit, Distance)) {
             Debug.Log(hit.transform.name);
             Debug.DrawRay(SightObject.transform.position, SightObject.transform.forward * Distance, Color.green);
             if (hit.transform.tag == "Player")
             {
                 Detected = true;
                 Enemy.gameObject.GetComponent<Enemy>().Distancia = Enemy.gameObject.GetComponent<Enemy>().DetectedDistance; 
                 Enemy.gameObject.GetComponent<Enemy>().LastDistance = Enemy.gameObject.GetComponent<Enemy>().DetectedLastDistance;  
             }
         }
     }
 }
 
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 DCordoba · Jan 24, 2019 at 12:42 AM 1
Share

here is a interesting and useful forum thread, with several approachs to solve this problem

avatar image el-mas-pro-470 DCordoba · Jan 24, 2019 at 01:39 AM 0
Share

Which?? So I already solve the question haha

1 Reply

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

Answer by xxmariofer · Jan 24, 2019 at 12:08 AM

Hello, sorry to not give you an answer in previous post but i didnt got notified, you cant easily do a cone with the rays, since you will have to instantitate a lot of rays in a circular direction and might also affect your performance, the easiest approach is to activate a object that works as a trigger, you can instantiate an object with a cone collider and do all that stuff in the ontriggerenter event, but you would have to refactor all your code, What was your problem from previous post? why wasnt detecting the player?

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 el-mas-pro-470 · Jan 24, 2019 at 12:26 AM 0
Share

Hello! thanks for answering, before the player was not detected because the script contained inesary parameters that filled the code and blocked the features, now I started one from 0 and it worked. P.S: How do I make several raycast rays to form a cone? (flat). since I saw this several times and it's a good idea!

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

141 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 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 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 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 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 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 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

raycast going through walls 0 Answers

Raycast from evemy to player is way to far down 1 Answer

How do I check if an specific object is NOT inside a trigger? 0 Answers

How to account for a failed raycast? 1 Answer

Touch - Linecast collision detection 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