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 eeveelution8 · Jul 12, 2014 at 11:56 PM · aienemypathfindingglitchisometric

Enemy units behave normally, until they rotate, then their AI seems to break

I have a turn based strategy game, and the enemy have (very basic)AI. The little units seem to work and behave normally, but once they rotate, their AI seems to blow a fuse and they speed up, go through walls, and teleport randomly across the level.

alt text

alt text

I have been working on it for the last 2 hours, and had no luck, but as proofreading has always taught me, if you don't pick up on errors, someone else will, so I'm asking anyone to take a look at it and see if I did something wrong.

 #pragma strict
 
 var sound1 : AudioClip;
 
 var Attack1 : GameObject;
 
 var MAXHP : float = 100;
 var HP : float = 100;
 
 var MAXAP : float = 10;
 var AP : int = 10;
 
 var Attackcost : int = 10;
 
 var Attacktype : String;
 
 var isitmyturn : boolean = false;
 var isinitiated : boolean = false;
 var amIalive : boolean = true;
 
 var mysoldier : GameObject;
 var detectionpoint : GameObject;
 var backdetectionpoint : GameObject;
 
 var livemodel : GameObject;
 var deadmodel : GameObject;
 
 
 
 function Update(){
 
 if(isitmyturn == true){
     if(isinitiated == false){
     
     if(amIalive == true){
     initiatemovement();
     isinitiated = true;
     }if(amIalive == false){
     isitmyturn = false;
     }
 
 }
 }
 
 
 
 if(HP <= 0){
     amIalive = false;
     
     livemodel.SetActive(false);
     deadmodel.SetActive(true);
     }
 
 
 }
 
 
 
 function initiatemovement(){
 yield WaitForSeconds(0.2);
 var fwd = mysoldier.transform.TransformDirection (Vector3.forward);
 if (Physics.Raycast (detectionpoint.transform.position, fwd, 2.1)) {
 
 var randomturn : float = Random.Range(0,100);
 
 if(randomturn > 50){
 yield WaitForSeconds(0.2);
 mysoldier.transform.Rotate(Vector3(0,90,0));
 checkforenemies();
 
 }
 
 if(randomturn <= 50){
 yield WaitForSeconds(0.2);
 mysoldier.transform.Rotate(Vector3(0,-90,0));
 checkforenemies();
 
 
 }
 
 
 }
 
 else
 {
 yield WaitForSeconds(0.2);
 mysoldier.transform.Translate(Vector3(0,0,2));
 AP -= 1;
 
 }
 
 yield WaitForSeconds(0.2);
 
 checkforenemies();
 
 }
 
 
 function checkforenemies(){
 yield WaitForSeconds(0.2);
 var hit : RaycastHit;
 var fwd2 = mysoldier.transform.TransformDirection (Vector3.forward);
 if (Physics.Raycast(detectionpoint.transform.position, fwd2,hit, 16)){
     
     if(hit.collider.gameObject.CompareTag("Player")){
     
 
     shoot1();
     yield WaitForSeconds(1);
     checkforAP();
     }
     
 if(hit.collider.gameObject.CompareTag("Untagged")){
 
 checkforAP();
 
 }
 
 }
 }
 
 function checkforAP(){
 yield WaitForSeconds(0.2);
 if(AP < 1){
 
 isitmyturn = false;
 isinitiated = false;
 yield WaitForSeconds(0.2);
 AP = MAXAP;
 }
 if(AP > 0){
 
 redo();
 
 }
 
 }
 
 function shoot1(){
 
 
 if(AP >= Attackcost){
 
     if(Attacktype == "single"){
         
         var instance1 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.clip = sound1;
         audio.Play();
         AP -= Attackcost;
     }
 
     if(Attacktype == "burst"){
         
         var instance2 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.clip = sound1;
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance5 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance6 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
         AP -= Attackcost;
     }
     
     if(Attacktype == "auto"){
         
         var instance26 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.clip = sound1;
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance7 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance8 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance9 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance0 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance11 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
             yield WaitForSeconds(0.1);
         var instance12 : GameObject = Instantiate(Attack1, detectionpoint.transform.position, detectionpoint.transform.rotation); 
         audio.Play();
         AP -= Attackcost;
     }
     
     
 }
 }
 
 function redo(){
 
 if(isitmyturn == true){
 if(isinitiated == true){
 
 isinitiated = false;
 
 }}
 }


Again, I suspect that the problem arises from lines 59-96. To test the script, place it on a cube that is 1x2x1 dimensionally, and place it at 0,0,0, and place 2x2x2 blocks scattered in front of it on a 2 block grid.

Any help with this problem is appreciated

pic2.png (73.1 kB)
pic1.png (73.2 kB)
Comment
Add comment
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

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

21 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

Related Questions

A* pathfinding avoidance 0 Answers

Obstacle avoidance not working 0 Answers

How to I make FindGameObjectWithTag() not just find itself? 1 Answer

Horde of NavMeshAgents - stops to recalculate path. 4 Answers

Object Avoidance for my enemies 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