Commit 8c74d0fa authored by Tanner Grehawick's avatar Tanner Grehawick

refactor CollisionState

parent 82d354a1
...@@ -23,34 +23,66 @@ public class CollisionState : MonoBehaviour { ...@@ -23,34 +23,66 @@ public class CollisionState : MonoBehaviour {
void FixedUpdate() { void FixedUpdate() {
enemyHit = null; enemyHit = null;
onGround = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, collisionLayer); // onGround = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, collisionLayer);
onWallLeft = Physics2D.OverlapCircle(body.position + leftPosition, collisionRadius, collisionLayer); // onWallLeft = Physics2D.OverlapCircle(body.position + leftPosition, collisionRadius, collisionLayer);
onWallRight = Physics2D.OverlapCircle(body.position + rightPosition, collisionRadius, collisionLayer); // onWallRight = Physics2D.OverlapCircle(body.position + rightPosition, collisionRadius, collisionLayer);
onWall = onWallRight || onWallLeft; // onWall = onWallRight || onWallLeft;
enemyHit = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, enemyLayer); enemyHit = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, enemyLayer);
} }
void OnDrawGizmos() { void OnDrawGizmosSelected() {
Gizmos.color = Color.red; Gizmos.color = Color.red;
Vector2 pos = bottomPosition; Vector2 pos = bottomPosition;
pos.x += transform.position.x; pos.x += transform.position.x;
pos.y += transform.position.y; pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius); Gizmos.DrawWireSphere(pos, collisionRadius);
pos = rightPosition; pos = rightPosition;
pos.x += transform.position.x; pos.x += transform.position.x;
pos.y += transform.position.y; pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius); Gizmos.DrawWireSphere(pos, collisionRadius);
pos = leftPosition; pos = leftPosition;
pos.x += transform.position.x; pos.x += transform.position.x;
pos.y += transform.position.y; pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius); Gizmos.DrawWireSphere(pos, collisionRadius);
}
void OnCollisionStay2D(Collision2D collision) {
onGround = false;
onWallLeft = false;
onWallRight = false;
foreach (ContactPoint2D contact in collision.contacts) {
Color color = Color.white;
Vector2 normal = contact.normal;
if (normal == Vector2.right) {
color = Color.red;
onWallLeft = true;
}
if (normal == -Vector2.right) {
color = Color.green;
onWallRight = true;
}
if (normal == Vector2.up) {
color = Color.blue;
onGround = true;
}
onWall = onWallLeft || onWallRight;
Debug.DrawRay(contact.point, contact.normal, color);
}
}
void OnCollisionExit2D() {
onGround = false;
onWallLeft = false;
onWallRight = false;
onWall = false;
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: c5db22d5529dd524b9174371b8f9af7a guid: c5db22d5529dd524b9174371b8f9af7a
timeCreated: 1486076722 timeCreated: 1488938661
licenseType: Free licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: -100
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment