As I am very new to this forum (i.e. 10 minutes ago) please forgive any formatting errors I may create.
I am attempting to create a 2d game that has a realistic space simulation. The map is supposed to be set so that you are looking from the top down. The problem I am having exists in my interaction between the sun and a planet. Simply put, the planet will only move in a single diagonal direction without ever changing direction. The formulas I am using are F=(G*M1*M2)/D^2 and A=F/M. If there are better formulas for my purpose please tell me. The code below is simplified so that I do not have to copy over the entire class for it to make sense.
(inside planet Class) double x; double y; double mass; double xForce; double yForce; double xAccel; double yAccel; double xVel; double yVel; (Inside SolarSystem Class) double sunX; double sunY; double sunMass; ArrayList<Planet> planets; public void update() xAccel=getAccelX(); yAccel=getAccelY(); xVel+=xAccel; yVel+=yAccel; x+=xVel; y+=yVel; public double getAccelX() double G=6.67*Math.pow(10,-11); double D=Math.pow(sunX-x,2); xForce=(G*sunMass*mass)/D; return xForce/mass; public double getAccelY() double G=6.67*Math.pow(10,-11); double D=Math.pow(sunY-y,2); xForce=(G*sunMass*mass)/D; return yForce/mass;
Things I have already tried:
1. Setting G to negative
2. changing the order of the subtraction in determining D
3. some weird pythagorean theorem thing someone suggested