Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Update()
- {
- IsCollidingOnTop = false;
- IsCollidingOnBottom = false;
- IsCollidingOnLeft = false;
- IsCollidingOnRight = false;
- if (IsAffectedByGravity) Velocity += World.Gravity;
- Position += Velocity;
- int left = CornerMin.X;
- int right = CornerMax.X;
- int top = CornerMin.Y;
- int bottom = CornerMax.Y;
- List<SSSPBody> bodiesToCheck = World.Bodies;
- for (int i = 0; i < bodiesToCheck.Count; i++)
- {
- SSSPBody body = bodiesToCheck[i];
- if (body == this || IgnoreCollisionDetectBodies.Contains(body) ||
- body.CollisionGroups.Any(IgnoreCollisionDetectGroups.Contains)) continue;
- int bodyLeft = body.CornerMin.X;
- int bodyRight = body.CornerMax.X;
- int bodyTop = body.CornerMin.Y;
- int bodyBottom = body.CornerMax.Y;
- if(SSSPUtils.IsOverlapping(this, body))
- {
- int encrX = 0;
- int encrY = 0;
- if (bottom < bodyBottom && bottom >= bodyTop) encrY = bodyTop - bottom;
- else if (top > bodyTop && top <= bodyBottom) encrY = bodyBottom - top;
- if (left < bodyLeft && right >= bodyLeft) encrX = bodyLeft - right;
- else if (right > bodyRight && left <= bodyRight) encrX = bodyRight - left;
- int numPxOverlapX = 0;
- int numPxOverlapY = 0;
- if (left < bodyLeft) numPxOverlapX = right - bodyLeft;
- else numPxOverlapX = bodyRight - left;
- if (top < bodyTop) numPxOverlapY = bottom - bodyTop;
- else numPxOverlapY = bodyBottom - top;
- if(numPxOverlapX > numPxOverlapY)
- {
- Position += new SSSPVector2(0, encrY);
- if (encrY <= 0) IsCollidingOnTop = true;
- }
- else
- {
- Position += new SSSPVector2(encrX, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement