Commit ec6b70a1 authored by Andrew Van Buren's avatar Andrew Van Buren

Merge branch 'master' of git.gmu.edu:gadig/birb into fixes

parents 79146561 a76b053a
......@@ -7,6 +7,7 @@ public class CollisionState : MonoBehaviour {
public LayerMask enemyLayer;
public float skinWidth = 0;
public float groundCheckDistance = 0.1f;
public float wallCheckDistance = 0.1f;
public bool onGround { get; private set; }
public bool onWallLeft { get; private set; }
......@@ -37,46 +38,50 @@ public class CollisionState : MonoBehaviour {
void FixedUpdate() {
// TODO: enemy hit stuff
RaycastHit2D hit;
onGround = CheckCollision(Vector2.down, groundCheckDistance);
onWallLeft = CheckCollision(Vector2.left, wallCheckDistance);
onWallRight = CheckCollision(Vector2.right, wallCheckDistance);
}
RaycastHit2D hit = Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
Vector2.down, // direction
groundCheckDistance, // distance
collisionLayer // layermask
);
onGround = hit.collider != null;
bool CheckCollision(Vector2 direction, float range) {
return Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
direction, // direction
range, // distance
collisionLayer // layermask
).collider != null;
}
float lastFixedTime;
void OnCollisionStay2D(Collision2D collision) {
if (Time.fixedTime != lastFixedTime) {
// only reset flags at the start of each frame
// (OnCollisionStay2D is called once for every collider this body is in contact with)
onWallLeft = false;
onWallRight = false;
lastFixedTime = Time.fixedTime;
}
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;
}
Debug.DrawRay(contact.point, contact.normal, color);
}
}
// void OnCollisionStay2D(Collision2D collision) {
// if (Time.fixedTime != lastFixedTime) {
// // only reset flags at the start of each frame
// // (OnCollisionStay2D is called once for every collider this body is in contact with)
// onWallLeft = false;
// onWallRight = false;
// lastFixedTime = Time.fixedTime;
// }
// 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;
// }
// Debug.DrawRay(contact.point, contact.normal, color);
// }
// }
void OnCollisionExit2D() {
// reset flags when we arent colliding with anything at all
onWallLeft = false;
onWallRight = false;
}
// void OnCollisionExit2D() {
// // reset flags when we arent colliding with anything at all
// onWallLeft = false;
// onWallRight = false;
// }
}
......@@ -150,7 +150,7 @@ public class Walk : AbstractBehavior {
//slow down y velocity
if(body.velocity.y < clingSpeed)
{
body.velocity = new Vector2(body.velocity.x, -clingSpeed);
body.velocity = new Vector2(0, -clingSpeed);
}
}
......
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