Search Unity

getting surface normal from character controller

Discussion in 'Editor & General Support' started by warby, Oct 10, 2011.

  1. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    we posted this bug via the "report a problem function in the editor but now i want to know if somebody in the community knows a workaround that doesnt involve raycasts:

    ---------------------------------------------------------------------------------------------------------------------------------------------

    This code snippet from the documentation here:

    http://unity3d.com/support/documentation/ScriptReference/ControllerColliderHit-normal.html

    claims we can get "The normal of the surface we collided with in world space".
    That is NOT the case ! The normal we get seems to be the inverted normal of the point we hit on the curvature of the character collider capsule! Rather than the surface normal of the object we collided with.
    See screenshot1.jpg for example we walked (left to right) over the peak/edge of a large rotated cube. the Debug.DrawRay function drew those red lines for us.
    Once the character controller approached the peak the "surface normal" starts bending upwards and than bends downwards again on the other side. That is not what the surface normals of a cube look like ! the result it should give us i photoshoped into the right screenshot in green !
    If you need further proof /visualization on how the "output"normals change based on which part of the round character collider bottom hits it than have a look at screenshot2.jpg that shows us slowly walking off an edge. Also note how much more narrow the normal angel falloff is compared to the first screenshot further suggesting that this has nothing to do with the surface normals of the standard unity cube primitive

    We could see practical application for both kinds of normal output so we are not arguing for removing the current one (that might break many other unity games that depend on it) but we desperately need the "real" functionality that works like the documentation claims it does ! So Please implement another(new) function that TRUELY gives us the surface normal without a raycast !


    ---------------------------------------------------------------------------------------------------------------------------------------------



     
  2. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I feel bad for you since on the beta list they just harassed you about posting to the beta list instead of providing constructive feedback.

    Normals are a pretty basic feature of unity. These could be messed up by the following:

    1. An import/export problem. It's a basic cube, what format did you export from and which program? Did you use OBJ or FBX? Or did you just use a Unity built-in cube? It's possible it's just the export process that got messed up.

    If you use a static OBJ, open it in a text editor and manually check the normals. Or import the model into something like Modo where you can trust it will report the model correctly. This could just be a bad normal issue.

    2. Recalculate normals. It's possible you had the right normals in your modeling program, but in code you called recalculate normals which overrides the correct normals. Just avoid calling this and use your original normals.

    3. Transform. Maybe the scale of your object is causing rounding errors. Or maybe your object is nested deeply in the hierarchy. Put the object in the root and set the transform position (0,0,0) rotation (0,0,0) and scale (1,1,1). Does it still happen?

    4. It's a box. Just manually create your own mesh and manually generate normals. Make an editor script that let's you select a face and manually set the normal for each face so you can make it look right.

    5. Shader. This could even be a shader issue that distorts the normals. It looks like the uvs stretched the texture and changed the normals by relatively the same amounts. Just use a standard diffuse shader does it still do the same?

    6. Interpolation. In the raycast, it gives you the vertex or the face. Rather than using the interpolated value, use the face to manually check the 3 verts on the surface and get the actually normal which is likely not interpolated.

    7. Average. It looks like the raycast is hitting on the corner of the box. So technically the raycast hit two faces and those vectors look like the average of the two surfaces.

    8. Done it before. As you can see in the terrain for our game, normals are working just fine - http://igmarauders.isotx.com

    Normals are a very basic function and I doubt that it's broken. It's most likely a content issue.
     
    Last edited: Oct 10, 2011
  3. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    thanks for actually looking into it and posting such a detailed debugging approch ! :)

    the stuff in the screenshots are unity standard cubes no meshes from us and a raycast to those places does give us the REAL normal so its not a content issue. just that part of the character controller/physX is not working.
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892