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. Dismiss Notice

First Time WEBGL game input & collider don't work?

Discussion in 'WebGL' started by Ryeath, Feb 2, 2017.

  1. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Hi,

    First time trying a WebGL build. Basically the Roll A Ball tutorial with additional levels. Works fine in the editor so I set up for a WebGL build then uploaded to itch.io. After figuring out how to get it uploaded I try to play it. Splash screens work, yay. Game screens load and the ball falls through the floor instead of colliding. Also the keys don't work. I have it scripted to press 'S' to start the ball rolling and 'Z', 'X', 'C' to rotate camera. None of the keys presses do anything.

    So I did a stand alone PC build, without changing anything in the game, and it works fine.

    I recall reading somewhere that the mesh collider (on the floor) should be set to convex, but when I do that in the editor, the ball falls through the floor.

    I am using Chrome to run the game on itch.io. I get a warning in Iexplorer that says it can't run WebGL and if I try to run it in Chrome from my computer I get a warning that says it can't run from the computer and must be put on the web, which is why I uploaded to itch.io.

    Not much info I suppose, but perhaps someone can point out a step I am missing or something.

    Thanks.
     
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,067
    I just tried this myself with the tutorial project from A$ and it works nicely.

    What Unity and browser version do you use? Does the completed scene from the tutorial project work for you>
     
  3. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Hi Schubkraft,

    First of all I figured out the keyboard issue. I have to click on the game window first before it will start recognizing the keyboard input. I must have misinterpreted the Doc's where it says it automatically accepts keyboard input.

    I also uploaded the roll a ball tutorial I did and that is working fine. https://ryeath.itch.io/test

    I compared the two games.

    Both have a sphere player with a Rigid body using gravity and non kinematic and a Sphere collider set as non trigger.
    Both have a floor with a mesh collider set to non convex.

    The main differences are the working sphere in the first is a primitive from unity and the second one, not working, is a low (mid) poly sphere with normal map from Blender. The working floor is a plane from Unity and the non working a plane with built in walls from Blender.

    Also in the one that is not working I had put in a delay before allowing the ball to move (simple bool flag in an if statement).I also (on level one) had a reset so if the ball went off the floor it would reset back to start.

    Once I figured out the keyboard issue I tried the game again and after the ball fell through and pressed start it reset back to the board and fell through again over and over until I tried moving the ball. Once I moved the ball it actually worked fine until I hit level three (level two is a different mechanic / object without physics) but level three didn't have a reset because the sphere can't leave.

    After all that I figured the issue was in my delay, somehow not allowing the physics to work right. So I tried re arranging my delay tactic but I must have did something wrong because now the ball doesn't roll at all in the game. But it was late and I went to bed at that point.

    I will do more experimenting tonight.

    But it is confusing when it all works right in the stand alone build.

    Using the latest stable build of Unity 5.3? and chrome to play the game in because I can't I Explorer to work WebGL.

    Sorry for the long story. Trying to give as much detail as I can.
     
    Last edited: Feb 3, 2017
  4. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Quick question.

    Does Unity, when building for WebGL application automatically convert mesh colliders to convex? Perhaps to save space or something.

    I did some more exploratory testing and I think I see what is happening and the only explanation I can come up with is if Unity converts the mesh collider to convex.

    Here is what I did.
    I created a second plane beneath the main floor of my game. I made both the main floor and test plane convex, expecting the sphere to drop through both. What I observed was the sphere dropped immediately below the main floor then fell slowly to the test plane where it stopped. Right then I saw what was happening. My main floor has an elevation change and when selected convex the green collider outline looks like a trapezoid. When I start the game the first thing it does is kick the sphere out of the collider volume then it falls slower by gravity until it lands on the test plane.

    That would explain why it works with non convex (the collider takes the shape of the mesh), why it works in the PC standalone (assuming it doesn't change to convex), why my tutorial Roll A Ball works (flat plane means very little volume on convex collider). The only logical conclusion is the WebGL build converts the mesh collider to convex.

    Or am I just nuts?
     
  5. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Ok, disregard that previous question. I went back into my Roll A Ball tutorial file and changed the floors to convex and the same thing happened, the ball would float above the floor on top of the convex collider. So that disproves my theory of Unity automatically changing mesh colliders to convex.

    Back to the drawing board.
     
  6. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    So I disabled my first scene and am starting the game on my second scene, which does not use physics, just transforms and triggers. That works fine. Then when scene two completes and goes to scene three, which uses physics, and I moved the sphere well above where the convex collider would have been, the sphere will fall through the floor then translates back to the start point 5 times and on the sixth time it will land on the floor and stay there. Then the level plays out fine after that.

    But consistently works in the editor. I have to admit I am so confused right now. I tried researching how to record the screen so I could show it, but couldn't find anything quick to use. Will try later.
     
  7. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    I added a test plane just above my main floor and the sphere lands on it just fine. I think I'm going to take this over to the physics forum.
     
  8. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    It seems my blender mesh doesn't like WebGL, so I cheated and added some basic planes from Unity just a bit over my floor from blender and turned off the renderer so the player doesn't see the plane. Just a work around. I will need to do a bunch of testing to figure out why blender meshes don't like WebGL.
     
  9. Kjaka

    Kjaka

    Joined:
    Dec 8, 2015
    Posts:
    18
    Having the same problem, anyone got a solution?
     
  10. AlexKolosov

    AlexKolosov

    Joined:
    Dec 20, 2014
    Posts:
    11
  11. waltran

    waltran

    Joined:
    Feb 23, 2017
    Posts:
    36
    mesh colliders is not stabil on webgl builds!
    valve fix pls! oops not valve unity fix pls!
     
    rob_ice likes this.
  12. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    @Schubkraft hello, I got problems with meshCollider in my WebGL build too.
    But me, i am using the mesh collider for raycasting on it, the raycast don't touch the mesh collider.
    i am working on 2017.4.3.f1 long time support.
    Is this problem even considered or are we in trouble ?
     
  13. rob_ice

    rob_ice

    Joined:
    Nov 11, 2016
    Posts:
    112
    Any update on this? Is hindering a current project I am working on. Convex hull also didn't change the behaviour.

    (Shoutout for Waltran for the Valve mention)