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

Box Collider (3D) Collisions, Corner Collisions / Edge Collision issue?

Discussion in 'Physics' started by POiD, Feb 17, 2015.

  1. POiD

    POiD

    Joined:
    Dec 18, 2013
    Posts:
    4
    Hello All,

    I've been doing a lot of reading over the alst 2 days to try and solve an issue I'm having with respect to collisions and box colliders. The reading I've done has led me to the possible issue being the "corner glitch" of box collider interactions that can be solved with the Ghost Vertices approach. I've seen no responses on how to implement such a thing in Unity, and the bug that was submitted about it, is in "Will not Fix" status. Thus my post here.

    Background:
    2.5D space ship game. Levels created from Cube prefabs with Box Colliders. Cubes are 16x16, while the player is similarly a cube but of 32 x 32 size.
    The box collider on the Player is not rotated (Rigidbody Freeze Rotation in X,Y and Z), just the image (child object) is. The child's current rotation is used to apply Forces in different directions on the player to allow for movement in X and Y.

    Hierarchy Setup

    PlayerCollider
    -> PlayerImage (Cube Mesh with Texture)

    I'm seeing 2 issues.
    Issue #1
    When moving along a 'wall' with spaces the edge of the player box seems to be catching and throwing the player up at angles. As the player is twice the size of the level cubes, I'm actually looking for this to not happen.

    PP
    X X X X X X X X X

    As you can see, the player can't fit into a hole, and I've prevented rotation of the PP object. Thus I'm looking for the physics reaction to be similar to a box hitting a long plane, with reflective "bounce" according to the perpendicular of the surface.

    Unfortunately I am actually also seeing this exact same issue when the level cubes are fitted with no spaces between them at all. The bounces aren't equal in angle on either side of the perpendicular.

    Issue #2
    When pushed up against the wall, and adding force in an agle to the wall (say 45 degrees), every now and then the physics engine will force the player to jump. This appears to be the more common edge catch glitch.

    This also results in the velocity of the object increasing even if I'm adding force almost directly into the wall.
    I was hoping to slide along the wall, with the movement slowed to only the force in the vector direction parallel to the wall.
    Friction doesn't seem to work in this situation as it doesn't slow the player if I continue to add force. And super high values of Friction seem to cause the 'bounce' to be completely different in angles as well.

    F
    PP
    XXXXXXXXXXXXXXXXXXXX

    F - source direction of force going into the wall.
    Let's call Y (up / down) and X (left /right)

    So how would I go about this 'contact' between the player and wall, causing only movement in the player with the X component of the Force? Thus if the force is almost directly down on the player, the slide along the wall would be very very slow. How do I achieve this?


    So the real question is, how do I go about solving the above?
    Can this be done using the Unity Physics engine?
    Do I need to forego unity physics and use another method?
    Ray casts and determine collision responses in code myself? (http://deranged-hermit.blogspot.co.uk/2014/01/2d-platformer-collision-detection-with.html)
    Custom Mesh collider of a cube with rounded edges (for the player only)? Would this solve the above?
    Another method I haven't come across in my multi-day search for answers?

    Note: As I'm doing this in a 3D world, using 3D objects, I cannot use 2D edge colliders as suggested in many other thread posts.

    UPDATE:
    I've gone ahead and started implementing a process to process my maps to basically combine box colliders for objects on the map next to a similar object. This will handle a number of situations where I am having Box Collider edging issues, as well as lower the number of colliders within the scene, which must be good for performance.

    However, I still have issues for situations similar to the following found on the map:

    YYYYYYYY
    X
    X

    The Ys will be 1 collider and nestled up against it the Xs will be another, but there will still be a join between them. Unfortunately the player can move in all directions (no gravity) and thus will be able to hit the 'edge' between Y and X, and cause invalid bounces.

    So I'm still trying to figure out how I can solve this issue? Suggestions? Bueller?
     
    Last edited: Feb 28, 2015
  2. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
  3. L_Vi

    L_Vi

    Joined:
    Mar 5, 2015
    Posts:
    9
    I too have been looking for an answer to this problem on the very basic level (a ball rolling over planes / cubes). The next idea I was about to try was combining the mesh while removing the overlapping vertices (thus removing the 'seam')... but I think I might try jknight-nc's layer switch approach first.