Search Unity

"Build and run" different from play mode!

Discussion in 'Getting Started' started by DoubleDigitDev, Mar 25, 2022.

  1. DoubleDigitDev

    DoubleDigitDev

    Joined:
    Jan 17, 2022
    Posts:
    28
    I just finished a freakishly long enemy behavior script. Everything is working perfectly and the script is fairly easy to read for how long it is! I'm extremely happy with the enemy AI when I test it in play mode, but when I "build and run" the enemy's speed decreases significantly when it is in it's agro state. I am not sure what to do and I have read my script over for any errors many times, any ideas? I appreciate any help that is given, thanks!
     
  2. DoubleDigitDev

    DoubleDigitDev

    Joined:
    Jan 17, 2022
    Posts:
    28
    The slowing happens specifically when I use
    transform.position = Vector2.MoveTowards(transform.position, player.position, (speed * angerMultiplier) * Time.deltaTime);
    , this line is to make the enemy chase the player
     
    Last edited: Mar 26, 2022
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    At the risk of being shot down for being a Grammar Nazi, watch the spelling on your scripts, they're case sensitive.
     
  4. DoubleDigitDev

    DoubleDigitDev

    Joined:
    Jan 17, 2022
    Posts:
    28
    I don't see it XD is it a problem with my code or just a spelling error? Can you point it out to me?
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Can you post the rest of the script? Can't tell what is going on because I can't see where those other variables are coming from.

    For example, if you were already applying Time.deltaTime to one of the other variables you are using, like your "speed" variable, I'd expect this kind of thing to happen. If that were the case, the higher your frame rate the slower the object would move. Builds typically can achieve higher frame rates than Play Mode because they get compile time optimizations and no longer have the Editor overhead.

    I don't see an obvious spelling or case sensitive issue with the line you posted. If you had one you'd be getting a compile error though.
     
    Last edited: Mar 29, 2022
  6. DoubleDigitDev

    DoubleDigitDev

    Joined:
    Jan 17, 2022
    Posts:
    28
    OH! That makes sense. I am using void "FixedUpdate()" along with multiplying my variables by Time.deltaTime, after turning "void FixedUpdate()" back into "void Update()" everything is working as expected. Thank you so much!