public Vector2 GetCeilDirection(Vector2 velocity) { Vector2 velocityNormalized = velocity.normalized; Vector2 ceilDirection = new Vector2(RoundingHelper.InvertOnNegativeCeil(velocityNormalized.x), RoundingHelper.InvertOnNegativeCeil(velocityNormalized.y)); return(ceilDirection); }
private void UpdateCollisions(Collision2D collision) { Vector2 allDirections = new Vector2(); foreach (ContactPoint2D contact in collision.contacts) { Vector2 direction = (contact.point - (Vector2)transform.position).normalized; Vector2 ceiledDirection = new Vector2(); if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) { ceiledDirection.x = RoundingHelper.InvertOnNegativeCeil(direction.x); } else { ceiledDirection.y = RoundingHelper.InvertOnNegativeCeil(direction.y); } allDirections += ceiledDirection; } Vector2 combinedDirection = VectorHelper.Clamp(allDirections, -1, 1); if (collisions.ContainsKey(collision.collider)) { collisions[collision.collider] = combinedDirection; } else { collisions.Add(collision.collider, combinedDirection); } }
public static Vector2 InvertOnNegativeCeil(Vector2 vector) { return(new Vector2(RoundingHelper.InvertOnNegativeCeil(vector.x), RoundingHelper.InvertOnNegativeCeil(vector.y))); }