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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
private double velocity = (Math.sqrt(Math.pow((launchX-newX), 2) + (Math.pow((launchY-newY),2))))/150; private double gravity = 1; private int launchX; private int launchY; private double initialX; private double initialY; synchronized public void move(){ 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))); } |