Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float distanceX = (entity2.x+entity2.velocityX) - (entity1.x+entity1.velocityX);
- float distanceY = (entity2.y+entity2.velocityY) - (entity1.y+entity1.velocityY);
- float minDistance = entity1.radius + entity2.radius;
- float distance = (float)Math.sqrt(distanceX * distanceX + distanceY * distanceY);
- float f = (minDistance - distance) / minDistance;
- if(distance < minDistance)
- {
- entity1.velocityX -= (f * f * distanceX * elasticity);
- entity1.velocityY -= (f * f * distanceY * elasticity);
- entity2.velocityX += (f * f * distanceX * elasticity);
- entity2.velocityY += (f * f * distanceY * elasticity);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement