Advertisement
StormWingDelta

PointToPointGravityWorking

Jun 21st, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. //Needs some work but I'm happy it works
  2. public void gravity(AnimatedSprite T)
  3.     {
  4.         //
  5.         //distance getter
  6.         double dist = this.DisToOther(T);
  7.         //double distX = Math.abs(this.center().X() - T.center().X());
  8.         //double distY = Math.abs(this.center().Y() - T.center().Y());
  9.         //double dist = Math.sqrt( Math.pow(distX, 2) + Math.pow(distY, 2) );
  10.         double force = (1.81 * (T.mass * 10)) / Math.pow(dist,2);//Math.pow()  * massA
  11.         double dirX = (T.center().X() - this.center().X()) / dist;
  12.         double dirY = (T.center().Y() - this.center().Y()) / dist;
  13.        
  14.         if(this.DisToOther(T) >= this.frameWidth())
  15.         {
  16.         //I'll be fixing this up with Velocity increment functions in a few
  17.             T.setXVelocity( (T.velocity().X() - (force * dirX)) );//T.velocity().X()
  18.             T.setYVelocity( (T.velocity().Y() - (force * dirY)) );
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement