Skip to content

Commit

Permalink
i believe this update will fix any and all issues with corner penetra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
prime31 committed Mar 4, 2014
1 parent f9083e8 commit b6fc72f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 41 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Awake()

void onControllerCollider( RaycastHit2D hit )
{
// bail out on plain old ground hits
// bail out on plain old ground hits cause they arent very interesting
if( hit.normal.y == 1f )
return;

Expand Down
40 changes: 0 additions & 40 deletions Assets/CharacterController2D/Scripts/CharacterController2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,42 +407,6 @@ private void moveVertically( ref Vector3 deltaMovement )
}
}


/// <summary>
/// this method feels like a bit of a hack. it gets called when there are no collisions detected by either the horizontal
/// or vertical checks (for example: http://cl.ly/UD8V/Screen%20Shot%202014-03-03%20at%203.55.53%20PM.png)
/// </summary>
private void performDiagonalChecks( ref Vector3 deltaMovement )
{
var isGoingUp = deltaMovement.y > 0;
var isGoingRight = deltaMovement.x > 0;
Vector3 ray;

// figure out which ray origin to use based on movement direction
if( isGoingRight && isGoingUp )
ray = _raycastOrigins.topRight;
else if( isGoingRight && !isGoingUp )
ray = _raycastOrigins.bottomRight;
else if( !isGoingRight && isGoingUp )
ray = _raycastOrigins.topLeft;
else
ray = _raycastOrigins.bottomLeft;


DrawRay( ray, deltaMovement, Color.white );

_raycastHit = Physics2D.Raycast( ray, deltaMovement, deltaMovement.magnitude, platformMask & ~oneWayPlatformMask );
if( _raycastHit )
{
Debug.Break();
var xSkinAdjustment = isGoingRight ? -skinWidth : skinWidth;
var ySkinAdjustment = isGoingUp ? -skinWidth : skinWidth;

deltaMovement.x = _raycastHit.point.x - ray.x + xSkinAdjustment;
deltaMovement.y = _raycastHit.point.y - ray.y + ySkinAdjustment;
}
}

#endregion


Expand All @@ -467,10 +431,6 @@ public void move( Vector3 deltaMovement )
moveVertically( ref deltaMovement );


if( !collisionState.hasCollision() && deltaMovement.x != 0 && deltaMovement.y != 0 )
performDiagonalChecks( ref deltaMovement );


// move then update our state
if( usePhysicsForMovement )
{
Expand Down

0 comments on commit b6fc72f

Please sign in to comment.