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 Hez · Feb 05, 2013 at 01:42 AM · c#aiflying

.move dose not work with AI C#

This is my first game, and I am having issues with my first attacking AI. The best AI code I could find uses controller.move, but when I did it they did nothing. I did declare controller, and my AI dose have a character controller on it, but that dose nothing. I even un collided everything in the world. I also tried transform.translate, that got it moving, but it moved through walls.

 using UnityEngine;
 using System.Collections;
 
 public class FlyingAI : MonoBehaviour {
     
     Vector3 moveDirection = Vector3.zero;
     float moveingsideways = 0;
     float moveingforwards = 0;
     float rising = 0;
     float gravatyy = 6;
     static public bool awakee = false;
     Vector3 Moveing;
     public float Heath = 10;
     public float Maxhightt = 1;
     public Rigidbody DeadScarab;
     
     public Transform LookAtTarget;
     Quaternion startingrotat;
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
         //find the controller
         CharacterController controller = GetComponent<CharacterController>();    
         moveingsideways = 0;
         moveingforwards = 0;
         rising = 0;
         
         
         
         
 
         
         if (LookAtTarget.position.x + 18 > transform.localPosition.x){
         if (LookAtTarget.position.x - 18 < transform.localPosition.x){
         if (LookAtTarget.position.z - 18 < transform.localPosition.z){
         if (LookAtTarget.position.z + 18 > transform.localPosition.z){awakee = true;}}}}
         
         if (LookAtTarget.position.x + 18 < transform.localPosition.x)    {awakee = false;}
         if (LookAtTarget.position.x - 18 > transform.localPosition.x)    {awakee = false;}
         if (LookAtTarget.position.z - 18 > transform.localPosition.z)    {awakee = false;}
         if (LookAtTarget.position.z + 18 < transform.localPosition.z)    {awakee = false;}
 
         
         
         if (awakee)
         {
         
         if (LookAtTarget.position.x - 2 > transform.localPosition.x){ moveingsideways += 5;}
         if (LookAtTarget.position.x + 2 < transform.localPosition.x){ moveingsideways -= 5;}
         if (LookAtTarget.position.z + 2 < transform.localPosition.z){ moveingforwards -= 5;}
         if (LookAtTarget.position.z - 2 > transform.localPosition.z){ moveingforwards += 5;}
             if (transform.localPosition.y < 1)
             {
                 rising = 7;
             }
             if (transform.localPosition.y > 1)
             {
                 rising = 5;
             }
             if (transform.localPosition.y == 1)
             {
                 rising = 6;
             }
         
         float totalfalling = rising - 6;
             
         Moveing.x = moveingsideways;
         Moveing.z = moveingforwards;                
         Moveing.y = totalfalling;
             
         controller.SimpleMove(Moveing * Time.deltaTime);
         if (transform.rotation.x != 0){ transform.localRotation = new Quaternion(0,0,0,0);}            
         if (transform.rotation.y != 0){ transform.localRotation = new Quaternion(0,0,0,0);}            
         if (transform.rotation.z != 0){ transform.localRotation = new Quaternion(0,0,0,0);}            
     }
         
         
         
         
             
         
     
     }
          void OnCollisionEnter(Collision collision) {
     if (collision.gameObject.tag == "Bullet")    
         {            Heath -= 5;        }
     if (Heath <= 0)
     {
             Rigidbody Falling;
             
             Falling = Instantiate(DeadScarab,transform.localPosition,transform.rotation)as Rigidbody;        
             Destroy(gameObject);}
         
         //DeadScarab
 
         }
     //outside code    
     
     
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Imankit · Feb 05, 2013 at 06:14 AM

OnCollisionEnter will not work on Character Controller

You have to take

 void OnControllerColliderHit(ControllerColliderHit collision) {
          if (collision.gameObject.tag == "Bullet")
         {
           Heath -= 5;
         }
         if (Heath <= 0)
         {
         Rigidbody Falling;
          
         Falling = Instantiate(DeadScarab,transform.localPosition,transform.rotation)as Rigidbody;
         Destroy(gameObject);}
          
         //DeadScarab
          
         }
         //outside code
          
          
         }
Comment
Add comment · Show 5 · 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
avatar image Hez · Feb 05, 2013 at 06:30 AM 0
Share

That made them immortal D: but they still did not move, so they were not that scary... It dose give me a new, fun error tho, "OnColisionEnter: script error" or something like that.

avatar image Imankit · Feb 05, 2013 at 08:17 AM 0
Share

$$anonymous$$ay tou haven't removed your OnCollision function... Is this script assigned to a character controller?

avatar image Imankit · Feb 05, 2013 at 08:19 AM 0
Share

If you want your AI to follow your Player then just LookAt your player and transverse in the forward direction of your AI

avatar image Hez · Feb 05, 2013 at 08:22 AM 0
Share

this is the script to get the enemy moving. The ai$$anonymous$$g at player is another script :D

avatar image Hez · Feb 05, 2013 at 08:23 AM 0
Share

and it is on the enemy prefab, not the player :D

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

10 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

Related Questions

Distribute terrain in zones 3 Answers

AI scripting Question. 2 Answers

Multiple Cars not working 1 Answer

AI Field of vision 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 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