Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void krockEffekt(Ball otherball) {
- distance = Math.pow(position.x - otherball.position.x, 2) - Math.pow(position.y - otherball.position.y, 2);
- dx = position.x - otherball.position.x / distance;
- dy = position.y - otherball.position.y / distance;
- Coord d = new Coord(dx,dy);
- Coord normD = d.norm();
- impuls=Coord.scal(velocity,normD) - Coord.scal(otherball.velocity,normD);
- double New_velocityX1 = velocity.x - impuls*normD.x;
- double New_velocityY1 = velocity.y - impuls*normD.y;
- double New_velocityX2 = otherball.velocity.x + impuls*normD.x;
- double New_velocityY2 = otherball.velocity.y + impuls*normD.y;
- velocity = new Coord(New_velocityX1,New_velocityY1);
- otherball.velocity = new Coord(New_velocityX2,New_velocityY2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement