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 bruninDx · Mar 28, 2016 at 01:18 AM · scripting problemaienemy aiai problems

AI Problem.

Hello guys,

I'am trying to make a simple sneak AI, when you press "C" the VisionDistance of the enemy decrease to 3, it works just when I have 1 enemy in the scene, but when I have more than one enemy, this just work with one of them. What i'am doing wrong ?

[UPDATE] Hello, I realized that it only ocurs when i try to change the var VisionDistance(EnemyScript) inside the PlayerScript, why this ?

 PlayerScript:
 bool Sneak;
 
 //Those are all the lines that change something in the EnemyScript
 if(Input.GetKeyDown (KeyCode.C))
 {
 Sneak = !Sneak
 if(Sneak == true)
 {
 EnemyScript.VisionDistance = 3;
 }
 else 
 {
 EnemyScript.VisionDistance = 5;
 }
 }
 
 
 EnemyScript:
 float VisionDistance;

 // I calculate the distance betwen Enemy and Player, if the Distance < VisionDistance I send a Ray in Player Direction, if hit = Player the Enemy Attack.

The way it works:

 PlayerScript:
 bool LessVision;
 
 //When Press C LessVision = true;
 //When Press C and LessVision = true --- LessVision = false
 ZombieScript:
 if (PlayerScript.LessVision == true)
 {
 MaxDistance = 3;
 }
 else
 {
 MaxDistance = 5;
 }

Sorry for my english. Thank You.

Comment
Add comment · Show 6
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 bruninDx · Mar 28, 2016 at 02:39 AM 0
Share

Hello, I realized that it only ocurs when i try to change the var VisionDistance(EnemyScript) inside the PlayerScript, why this ?

Thanks

avatar image Ali-hatem · Mar 28, 2016 at 12:36 PM 0
Share

provide your code this way no one can help !

avatar image bruninDx Ali-hatem · Mar 28, 2016 at 02:16 PM 0
Share

Hello, i added the code, sorry for this.

avatar image Ali-hatem bruninDx · Mar 28, 2016 at 02:57 PM 0
Share

it is not clear how do you calculate the distance between Enemy and Player but i think you use bool Sneak; to deter$$anonymous$$e if there is a snake in the scene . will bad idea ins$$anonymous$$d use FindGameObjectsWithTag ("") :

 GameObject [] Sneaks;
 void Update(){
          Sneaks = GameObject.FindGameObjectsWithTag ("Snake");
 }

this way will find all game objects tagged Snake & store them in array

avatar image OllysCoding · Mar 28, 2016 at 02:05 PM 0
Share

Can you please provide your code? Without it we cannot see what the problem might be.

avatar image bruninDx OllysCoding · Mar 28, 2016 at 02:16 PM 0
Share

Hello, i added the code, sorry for this.

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

76 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

Related Questions

Need help with physics base enemy AI movement 1 Answer

Disable a Function when another and active (javascript AI) 1 Answer

Raycast Enemy AI shooting script 1 Answer

Flying ship AI 0 Answers

Interesting Enemy AI issue 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