Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Translate not working? Enemy stuck

Discussion in '2D' started by ARLC-753, Jul 17, 2021.

  1. ARLC-753

    ARLC-753

    Joined:
    Feb 2, 2021
    Posts:
    9
    I really do not know what the problem is, I made an Enemy-Behaviour script where basically the enemy patrols (moves left to right) and when the player enters the enemy's detection range by a onTriggerEnter2D the enemy stops "patrolling" and follows the player while the distance between the player and enemy is less than 7, when the distance gets larger the enemy stops "following" and resumes "patrolling".

    Literally, it all worked perfectly, then all of a sudden I make some changes in my code for the enemy to attack (I create an attack animation) and write some more stuff.

    After that, when I test it again the enemy is stuck, he moves but moves very slow (I checked in debug mode and the distance traveled (from it's starting position and the direction whe is supposed to advance) is from 0.000 something to 0.0007. Everything that I wrote that was "new" I changed into a comment so It wouldn't interfere, meaning, the code was exactly the same as before when it DID work, but when I run it the situation is the same, why? I have absolutely no idea.

    Im even thinking the problem may be from unity, I do not know if reimporting the script or deleting the enemy and creating him again as a prefab would solve it, I do not see how but at this point im at a complete loss.

    Also, when the code worked, each time the player entered the enemy's trigger box the console displayed a "Player detected" message, for each time the player entered (meaning that for it to display it twice the player had to exit and then re enter), but now, the message pops up infinitely while in the trigger box, again, I don't know.

    My code






    Hopefully someone can provide me with clues, I honestly do not think there is something wrong with the code, at least I don't see what since it worked perfectly before I added the things in the comments to the script
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Hey,

    Can you copy/paste your entire script using the insert code button please:
    Example.JPG
     
  3. ARLC-753

    ARLC-753

    Joined:
    Feb 2, 2021
    Posts:
    9
    Thanks, all fixed now