Commit 5c8d5847 authored by Tanner Grehawick's avatar Tanner Grehawick

fix animation stutter at tile borders

parent f45ee651
This diff is collapsed.
......@@ -5,22 +5,29 @@ public class CollisionState : MonoBehaviour {
public LayerMask collisionLayer;
public LayerMask enemyLayer;
public bool onGround, onWall, onWallRight, onWallLeft;
public Vector2 bottomPosition = Vector2.zero;
public Vector2 rightPosition = Vector2.zero;
public Vector2 leftPosition = Vector2.zero;
public float collisionRadius = 1f;
public float skinWidth = 0;
public float groundCheckDistance = 0.1f;
[HideInInspector]public Collider2D enemyHit;
public bool onGround { get; private set; }
public bool onWallLeft { get; private set; }
public bool onWallRight { get; private set; }
public bool onWall {
get {
return onWallLeft || onWallRight;
}
}
private InputState inputState;
private Rigidbody2D body;
private Animator animator;
private CircleCollider2D circle;
void Awake() {
inputState = GetComponent<InputState>();
body = GetComponent<Rigidbody2D>();
animator = GetComponentInChildren<Animator>();
circle = GetComponent<CircleCollider2D>();
}
void Update() {
......@@ -29,46 +36,25 @@ public class CollisionState : MonoBehaviour {
}
void FixedUpdate() {
// TODO: enemy hit stuff
RaycastHit2D hit = Physics2D.CircleCast(
circle.bounds.center, // center
circle.radius - skinWidth, // radius
Vector2.down, // direction
groundCheckDistance, // distance
collisionLayer // layermask
);
onGround = hit.collider != null;
enemyHit = null;
// onGround = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, collisionLayer);
// onWallLeft = Physics2D.OverlapCircle(body.position + leftPosition, collisionRadius, collisionLayer);
// onWallRight = Physics2D.OverlapCircle(body.position + rightPosition, collisionRadius, collisionLayer);
// onWall = onWallRight || onWallLeft;
enemyHit = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, enemyLayer);
}
// void OnDrawGizmosSelected() {
// Gizmos.color = Color.red;
// Vector2 pos = bottomPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// pos = rightPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// pos = leftPosition;
// pos.x += transform.position.x;
// pos.y += transform.position.y;
// Gizmos.DrawWireSphere(pos, collisionRadius);
// }
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)
onGround = false;
onWallLeft = false;
onWallRight = false;
lastFixedTime = Time.fixedTime;
......@@ -84,20 +70,13 @@ public class CollisionState : MonoBehaviour {
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() {
// reset flags when we arent colliding with anything at all
onGround = false;
onWallLeft = false;
onWallRight = false;
onWall = false;
}
}
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