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 pognoss · Oct 08, 2012 at 01:08 PM · movementenemymoveautomaticbetween

bug Move Automatic

Hi everybody! I have created an enemy. This character can move only on axis X ( so left or right ). If this character has detected the player, he can change the direction and accelerate. It's ok. But if the enemy is blocked between the player and an other object, he bug and he can't move after. The problem is my code or others?

My scripts here: Script Movement:

 using UnityEngine;
 using System.Collections;
 
 public class MoveEnemy : MonoBehaviour {
 
     public GameObject mesh;
     public Texture2D[] texMove;
     private int selectedTex;
     public float texUpdateTime;
     private float tmpTexUpdateTime;
     public float moveSpeed;
     public static float move;
     public static Vector3 direction;
     private Transform player;
     private Vector3 relative;
     private Transform character;
     // Use this for initialization
     void Start () {
         move = moveSpeed;
         direction = Vector3.right;
         player = GameObject.FindWithTag ("Player").transform;
         
     }
     
     // Update is called once per frame
     void Update () {
             MoveUpdate();    
             TexUpdate();
     }
     
         void TexUpdate()
     {
         // temporisation entre les texture (0,15s)
         // on change pas de texture tant que les 0,15s ne sont pas écoulé
         if (tmpTexUpdateTime > texUpdateTime)
         {
             tmpTexUpdateTime = 0; // remise à 0 du temps d'attente entre les textures
             selectedTex++; // on passe au mouvement suivent;
             if (selectedTex > texMove.Length - 1) // si on dépasse le nombre d'image du tableau 'texMove'
             {
                 selectedTex = 0; // on remet à la selection à 0
             }
             mesh.renderer.material.mainTexture = texMove[selectedTex]; // on ajoute la texture séléctionné
         }
         else
         {
             tmpTexUpdateTime += 1 * Time.deltaTime; // temps d'attente en fonction du temps
         }
     
     }    
     
     void MoveUpdate(){
         // Mouvement de l'enemy
         transform.Translate( direction * move * Time.deltaTime);
         // changement de coté en fonction de la position
         mesh.transform.localScale = new Vector3(direction.x,1,1);
         transform.localScale = new Vector3(direction.x,1,1);
         
     }    
     
 }

Script IA: using UnityEngine; using System.Collections;

 public class AI : MonoBehaviour {
     
     private Transform player;
     private Transform character;
     private bool insideInterestArea = true;
     private float  LefOrRight;
     public static bool spotted;
     RaycastHit hit;
     
     void Start () {
         character = transform;
         player = GameObject.FindWithTag ("Player").transform;
     }
     
     
     void Update () {
     
     }
     
     void OnTriggerEnter(Collider other)
     {
         if (other.transform == player && CanSeePlayer()) 
         {
             OnSpotted();
             
         }
 
     }
     
 
     bool CanSeePlayer(){
         Vector3 playerDirection = (player.position - character.position);
         Physics.Raycast (character.position, playerDirection, out hit, playerDirection.magnitude);
         if (hit.collider && hit.collider.transform == player) {
             return true;
         }
         return false;
     
         
     }
     
     void OnSpotted(){
             MoveEnemy.direction.x *= -1;
             MoveEnemy.move *= 2;
             spotted = true;
     }    
 }

Thanks you for yours answers.

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 Fattie · Oct 08, 2012 at 01:15 PM 0
Share

you have to use the physics LAYERS system.

it's critical to game progra$$anonymous$$g !

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pognoss · Oct 08, 2012 at 04:03 PM

Ok,i'm reading your link, but i change the the Physics Preference Panel by clicking on Edit->Project Settings->Physics but no change in my problem. Do you can explain to me please?

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy move error 2 Answers

How to make enemies stop a certain distance away? 2 Answers

Object moving OnTriggerEnter, please help?! 2 Answers

Move enemy ship down while moving left and right 2 Answers

Moving AI away or towards player not working correctly. 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