Search Unity

Physics going haywire when game is built - Please help!

Discussion in 'Physics' started by Bionicle_fanatic, Nov 26, 2014.

  1. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Hi, I've got a horrible glitch that's practically made a month's work useless unless I can fix it.

    I'm making a 2D platform/sidescroll game. It works fine in the editor. It also works fine as a standalone build. And, get this, it also works fine on some computers (seemingly random) when I build it for webplayer. However, on about 50% of my tester computers have the glitch with it (webplayer build).

    The glitch is basically a physics one, where AddForce seems to be blown massively out of proportion: The projectiles are zooming off screen, the enemies are so fast there's no way you can escape, etc. I could probably fix it, if I knew why it's doing it. It just doesn't make sense: On one computer it's fine, on the next it's practically broken.

    Please, please help.
     
  2. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Not enough info man! Are you randomizing something?
     
  3. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Nope. It's just a simple AddForce, called once when the projectile is instantiated, or the AddForce called multiple times in the LateUpdate function and times by Time.deltaTime. Here's what works and what doesn't:

    In my Macbook Pro:
    Editor: Works
    Standalone: Works
    Web Build: Works

    On our highly-powered Mac mini:
    Editor: Works
    Standalone: Works
    Web Build: Doesn't work

    On my bro's new PC:
    Web Build: Doesn't work

    On my sister's old-er PC:
    Web Build: Works

    I thought it might be to do with the speed of the computers, as it seemed to glitch only on faster computers. Then I tested it in standalone/editor on the Mac mini, and it worked fine, so that blew that theory to pieces.
     
  4. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Time.deltaTime

    That's the only thing that isn't a constant.

    You should start logging from that object, monitor it's velocity moment by moment, something's adding funky velocity. All the machine stuff is not relevant, as Unity has been extensively put through its paces through many years. The problem is more likely in your source, just have to find what you're doin/not doing.
     
  5. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Umm, Time.deltaTime is constant, that's why you times the AddForce velocity by that to make it smooth. I just tried it using Time.fixedDeltaTime, and it still doesn't work.

    And there is no problem in the source: It works fine in the editor. It works fine on 50% of the computers. There should technically be no reason why it's not functioning properly.

    I maybe thought it was something to do with how the game is compiled... has there been any errors with that? I do have an older version of Unity, y'know (4.3)
     
  6. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    deltatime is not constant. It would be literally worthless if it was.

    Deltatime is the time since the last frame. Which, if your game is running at a smooth/consistent framerate, will be ALMOST constant from frame to frame. Even with a capped framerate i doubt it's ever 100% predictable

    When your framerate is not smooth, like if you're swapping rapiudly between millions of collisions, and none, deltatime can vary hugely. That's the point of it. It adapts to how well your game is performing.
     
    RJ-MacReady likes this.
  7. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    My theory is that deltatime might be spiking randomly, since I know literally nothing else about his game.
     
    Nanako likes this.
  8. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    I found out what it was: For some reason the older version of Unity clones the colliders or something when the game is built, and that's what makes it behave erratically. So I just updated to the newest version. Problem solved.
     
    RJ-MacReady likes this.
  9. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    delta time is how much time took last frame rendering. Its not constant obviously
     
  10. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Good job.