Skip to content

Commit

Permalink
Fixed the squeeze-between bug
Browse files Browse the repository at this point in the history
Fixed a bug that let Merky squeeze between two solid blocks
  • Loading branch information
shieldgenerator7 committed Mar 17, 2016
1 parent ecc47d4 commit 4a9c1ff
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ bool isOccupied(Vector3 pos)
foreach (Vector3 checkDir in checkDirs)
{
Vector2 dir2 = new Vector2(checkDir.x, checkDir.y);
float length = 0.01f;// 1.7f;
float length = 0.4f;// 1.7f;
dir2 = dir2.normalized * length;
Vector2 start = (pos2 + dir2);
//Debug.DrawLine(pos2, start, Color.black, 1);
Expand All @@ -398,7 +398,19 @@ bool isOccupied(Vector3 pos)
GameObject ground = rch2d.collider.gameObject;
if (ground != null && !ground.Equals(transform.gameObject))
{
return true;//yep, it's occupied
//test opposite direction
start = (pos2 + -1*dir2);
rch2d = Physics2D.Raycast(start, dir2, length);
Debug.DrawLine(start, start+dir2, Color.black, 1);
if (rch2d && rch2d.collider != null)
{
ground = rch2d.collider.gameObject;
if (ground != null && !ground.Equals(transform.gameObject))
{
return true;//yep, it's occupied on both sides
}
//nope, it's occupied on one side but not the other
}
}
}
}
Expand Down

0 comments on commit 4a9c1ff

Please sign in to comment.