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 /
avatar image
0
Question by tokenshi · Jul 20, 2011 at 05:05 PM · transformaiswitch-case

AI Case Switch Issue - Javascript, 2D Shooter

First the code:

 function Update () {
 player = 
 CheckStatus();
 print ("Checking Status");
 switch(status)
 {
 case AIStatus.Idle:
 print ("Idling");
 Idle();
 break;
 
 case AIStatus.Firing:
 print("Activating Firing");
 Firing();
 break;
 
 }
 
 
 }
 //does successfully switch between idle and scared one time, and one time only.
 function CheckStatus () {
 
 //dist = (player.position - this.transform.position).magnitude; //not updating for some reason
 dist = (player.position.z - this.transform.position.z); //not updating for some reason
 if (dist < fireDistance) {
 status = AIStatus.Firing;
 print ("AI is Firing at dist:" + dist);
 }
 if (dist > awareDistance) {
 status = AIStatus.Idle;
 print ("AI is Idle at dist: " + dist);
 }
 
 
 }
 function Idle() {
 
 
 }
 
 function Firing() {
 
 
 }

Now the issue:it appears that CheckStatus() never updates the dist variable, and always shows the initial distance. The result is it's always stuck in one state or the other. In other words - it's either always idling, or always firing.

Halp

edit: The issue was apparently with dist always reading negative. Solved by taking a negative of the whole equation.

Comment
Add comment · Show 4
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 almo · Jul 20, 2011 at 05:19 PM 0
Share

Format your code using the 010101 button.

avatar image tokenshi · Jul 20, 2011 at 05:35 PM 0
Share

Oh yeah! sorry, didn't notice that.

Thanks for looking out

avatar image Dreamblur · Jul 20, 2011 at 05:46 PM 0
Share

What's this about?

 player = 
avatar image Dreamblur · Jul 20, 2011 at 06:05 PM 0
Share

Do the values of fireDistance and awareDistance overlap? If they don't, then it's possible that the calculated distance is bouncing back and forth against the endpoints of that outside range, thus never getting caught.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tokenshi · Jul 20, 2011 at 05:57 PM

gah, not sure what happened there, but it didn't copy the whole line. It should read:

 player = GameObject.Find("Player(Clone)").transform;
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

Boids for 2D 0 Answers

object pauses at the each way points for a vary short time 1 Answer

Transform.translate change 1 Answer

Simple Sentry Guard Creation Help 2 Answers

NavMeshAgent places transform incorrectly 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