Hey everyone,
This is my first game I have ever attempted and am running into road blocks left and right. At this point in the program I have a rock that is thrown from the origin towards x,y coordinates of a left mouse click. I want to have this rock thrown in a fairly realistic parabola using the magnitude of the throw (given by distance of click from origin), and angle of throw from the origin.
At this point I have written and rewritten the move method many times and simply can’t get it to work. I understand the physics and the math of it, but not how to translate them into java. I’ve looked at a lot of examples but can’t figure out how to apply it. Most of them talk about using time, but I am not sure how to apply it. Really any help will make a huge difference for me.
private double velocity = (Math.sqrt(Math.pow((launchX-newX), 2) + (Math.pow((launchY-newY),2))))/150; // c^2 = sqrt(a^2 + b^2)
private double gravity = 1;
private int launchX; // mouse input
private int launchY; // mouse input
private double initialX; // origin
private double initialY; // origin
synchronized public void move(){
//currentTime = System.nanoTime() - startTime;
if(newY < upperMax){
active = false;
}
theta = (float) Math.toDegrees(Math.atan2(launchX - initialX, launchX - initialY));
newX = (int)(newX + ((moveSpeed * velocity)));
newY = (int)(newY + ((-velocity + (gravity * velocity)) * -Math.cos(theta)));
} // end move