I'm trying to make a little physics engine and want to move one planet towards another planet using setLocation(). basically, what i've been doing is using turnTowards() to turn one planet towards another planet, then the move() method to move the planet to the other planet. this does work technically, but I basically want to add angular momentum so the planet doesn't go straight towards the other objects. I don't know if that made any sense, but hopefully yall can help.
This is all my code for the Planet1 class. any help regarding making a physics engine or my specific problem would be appreciated!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Planet1 here. * * @author (your name) * @version (a version number or a date) */ public class Planet1 extends Planets { private final int gravityConstant = 3; private int mass; private int radius; private int gravity; public Planet1(int mass) { this.mass = mass; } public void act() { calculateGravity(); detectPlanet(); } public void detectPlanet() { List<Planet1> planets = getObjectsInRange(600, Planet1.class); if(!planets.isEmpty()) { Actor planet = (Actor)planets.get(0); planet.turnTowards(getX(), getY()); planet.move(gravity); } } public void calculateGravity() { radius = getImage().getWidth()/2; gravity = (gravityConstant * mass) / (radius * radius); } }