Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. float distanceX = (entity2.x+entity2.velocityX) - (entity1.x+entity1.velocityX);
  2. float distanceY = (entity2.y+entity2.velocityY) - (entity1.y+entity1.velocityY);
  3. float minDistance = entity1.radius + entity2.radius;
  4. float distance = (float)Math.sqrt(distanceX * distanceX + distanceY * distanceY);
  5.  
  6. float f = (minDistance - distance) / minDistance;
  7.  
  8. if(distance < minDistance)
  9. {
  10. entity1.velocityX -= (f * f * distanceX * elasticity);
  11. entity1.velocityY -= (f * f * distanceY * elasticity);
  12.  
  13. entity2.velocityX += (f * f * distanceX * elasticity);
  14. entity2.velocityY += (f * f * distanceY * elasticity);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement