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 ssoulreaper · Feb 08, 2014 at 05:51 PM · aitargeting

AI Player detect without having a target before detect.

Trying to figure out if a single ray can be fanned out. tying to get AI to detect player within a fov range. I have it on my player so that I can test it out before I transfer it. At the moment it only detects the line which is 1. to about only 0.8f. either side rotates. Am trying to make it where it will go to 0 on rotation or around 45 degrees on either. So far ray is lacking for this.

 void SeePlayer() {
         RaycastHit hit;
         Ray seenRay = new Ray(Player.transform.localPosition, Player.transform.forward);
         
         Debug.DrawRay(Player.transform.localPosition, Player.transform.forward * 10.0f, Color.red);
         
         if(Physics.Raycast(seenRay, out hit, meleeAttackDistance))
         {
             if(hit.collider.tag == "Enemy")
             {
                 if(Vector3.Distance(hit.transform.localPosition, Player.transform.localPosition) < 10.0f)
                 {
                     if(Vector3.Dot((hit.transform.localPosition - Player.transform.localPosition).normalized, Player.transform.forward) > 0) 
                     {
                         Debug.Log("HIT");
                     }
                 }
             }
         }    
     }

Trying to use Vector3.Dot() to get it when an object moves into this FOV that it will know something is their to go attack it.

My AI will not have a player Selected as a Target yet, so i tried modifying this code.

 if(Vector3.Distance(Target.transform.localPosition, Player.transform.localPosition) < 10.0f)
     {
         if(Vector3.Dot((Target.transform.localPosition - Player.transform.localPosition).normalized, Player.transform.forward) > 0) {
             Debug.Log("Hit");
         }
     }

Is their a way without raycast to check if a collider with a rigidbody enters inside of the FOV cone without needing a collider object to detect with an OnTriggerEnter? Needs to be able to detect without knowing what its target could be before hand.

Comment
Add comment · Show 1
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 Shmks · Aug 17, 2014 at 11:30 PM 0
Share

I have a similar problem. I haven't implemented it yet, but what I think might work is casting a cone of rays out at the correct angle of view, in this case 45 degrees. The greater the distance, the more rays you need to cast to keep things from slipping between, but I think it will work if the range is reasonable and the target isn't too small.

If you get a hit, then you can get the target position and just check that it stays within your 45° angle. I'll post my code if I get this to work.

EDIT:

Just came across this post, which also has some good info: http://answers.unity3d.com/questions/284685/regarding-the-efficiency-of-enemy-detection.html

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

19 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

Related Questions

Ai Targetting feet instead of my body 2 Answers

faster target selection 2 Answers

2d AI: enemy targeting c# 2 Answers

C# Targetting Help 1 Answer

How to determine a "cone of influence" used for targeting an object. 2 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