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 07:58 PM · enemyraycastingnot workingstealthnothing

Enemy ignore walls in sight! Help!

Hello again, I made a vision script in raycast, but NOTHING works, I need a vision of SIMPLE RAYCAST but I did not find anything, all are very difficult tutorials for me, I look for a line in which the OBJECTIVE when entering a VISION CONE that DO NOT traverse the walls, that is, alter when the player is visible (raycast), the enemy is altered by the Booleans (I already do but the raycast receives nothing anywhere) I asked a question before about this but not It helped and I do not receive answers. This is my script:

 using System.Collections;
 
 public class EnemyRaycast : MonoBehaviour {
 
     Ray ThugRay;
     RaycastHit RayHit;
     public float Distance;
     public float DetectedDistance;
     public bool Detected = false;
     public Transform Target;
     private int delayCount = 0;
     private int maxDelay = 10;
     public bool wasLastVisible = false;
 
     void Start () 
     {
     
     }
     
     void Update(bool IsPlayerVisible) {
         delayCount++;
         if (delayCount == maxDelay) {
 
             delayCount = 0;
             
             Vector3 dir = Target.position - transform.position;
 
             RaycastHit hit;
             if (Physics.Raycast(transform.position, transform.forward, out hit)) {
                 if (hit.transform.tag.Equals("Player"))
                     wasLastVisible = true;
                     else{
                     wasLastVisible = false;
                     }
                     }
         }
     }
 }
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 xxmariofer · Jan 23, 2019 at 08:36 PM 0
Share

Can you put a Debug.Log just after the Physics.Raycast? Just for making sure if its not colliding to any other object copy this line between both ifs

Debug.Log(hit.collider.gameObject.name);

and tell us whats logging, also try this line next to the debu.log so you now where the ray is going

Debug.DrawRay(transform.position, transform.forward, Color.green);

avatar image el-mas-pro-470 xxmariofer · Jan 23, 2019 at 09:20 PM 0
Share

Thanks, I'll prove it

avatar image el-mas-pro-470 el-mas-pro-470 · Jan 23, 2019 at 09:42 PM 0
Share

I did it but it does not mark anything to me, since recently it gives me an error of the Void Update (bool isplayervisible), it was Boolean. the drawray simply do not working. Do you know how to do a simple range of vision? Thank you

     void Boolean (bool IsPlayerVisible) {
         delayCount++;
         if (delayCount == maxDelay) {
 
             delayCount = 0;
             
             Vector3 dir = Target.position - transform.position;
 
             RaycastHit hit;
 
             if (Physics.Raycast(transform.position, transform.forward, out hit)) {
                 Debug.Log(hit.collider.gameObject.name);
                 if (hit.transform.tag.Equals("Player"))
 
                     wasLastVisible = true;
                     else{
                     wasLastVisible = false;
                     }
                     }
         }
     }
 }

0 Replies

· Add your reply
  • Sort: 

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

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

Having trouble with player health 0 Answers

How to activate "OnTriggerEnter" when Player ray hits an object collider? 1 Answer

Graphic Raycaster doesnt take into account fill image parameter. 0 Answers

Raycast is not hitting collider 2 Answers

Is there a way for creating composite raycast collisions ? 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