Ballistics ( Bow - Arrow ) - is this Right?

Heya Guys!
Well im trying to make a little model of Ballistics to later implement in my game… I have something like this :

package balistica;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
 *
 */
class View implements ApplicationListener, InputProcessor {

    private SpriteBatch batch;
    private Sprite ball;
    private Sprite box;

    private int boxPosX, boxPosY;
    public double ballPosX, ballPosY;

    private double angle;
    private double frameTime;

    @Override
    public void create() {
        Gdx.input.setInputProcessor(this);

        ball = new Sprite(new Texture(Gdx.files.internal("ball.png")));
        box = new Sprite(new Texture(Gdx.files.internal("cTest.png")));
        batch = new SpriteBatch();

        boxPosX = 10;
        boxPosY = 10;

        ballPosX = 0;
        ballPosY = 0;

        frameTime = -1;

    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        
        if (frameTime >= 0) {
            //getSX(double xo, double yo, double vo, double gravity, double angle, double time)
            ballPosX = Update.getSX(10,10,50,1, angle, frameTime);
            //getSY(double yo, double vo, double gravity, double angle, double time)
            ballPosY = Update.getSY(10,50, 1, angle, frameTime);

            System.out.println("x;y" + ballPosX + ";" + ballPosY);
            frameTime = frameTime + 0.1;
        }

        batch.begin();
        batch.draw(box, boxPosX, boxPosY);
        batch.draw(ball, (int) ballPosX, (int) ballPosY);
        batch.end();

    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
    }

    @Override
    public boolean keyDown(int keycode) {
        return true;
    }

    @Override
    public boolean keyUp(int keycode) {
        return true;
    }

    @Override
    public boolean keyTyped(char character) {
        return true;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        angle = Update.getAngle(boxPosX, screenX, boxPosY, screenY);
        System.out.println("Box = (" + boxPosX + ";" + boxPosY + ")");
        System.out.println("Screen = (" + screenX + ";" + screenY + ")");

        System.out.println("Angle" + angle);

        frameTime = 0;
        return true;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        return true;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        return true;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        return true;
    }

    @Override
    public boolean scrolled(int amount) {
        return true;
    }

}

package balistica;

public class Update {

    public static double getAngle(double xi,double xf, double yi, double yf) {
        double atan = Math.atan((yi-yf)/(xi-xf));

        return atan;
    }

    public static double getSX(double xo, double yo, double vo, double gravity, double angle, double time) {
        double dx = (xo + vo) * Math.cos(angle) * time;

        return dx;
    }

    public static double getSY(double yo, double vo, double gravity, double angle, double time) {

        double dy = (yo + vo) * (Math.sin(angle)) * (time - ((gravity / 2)) * (time * time));

        return dy;
    }

}

Im not sure its working… Would anyone have a look preety please?

You’ll need to provide more details as to what the problem is. Sorry, I’m not going to sit here and try to guess what your code does.

Ah im sorry,

well its a calculation to get the X;Y of the arrow after shooting it. It gets the angle and then you can use the angle to calculate.

It was incorrect. I still need to make some fixes but, heres what i changed so far :

package balistica;

public class Update {

    public static void main(String args[])
    {
        double angle = getAngle(20,200,20,200);
        System.out.println(angle);
    }
    
    public static double getAngle(double xi,double xf, double yi, double yf) {
        
        
        double atan = Math.atan((yi-yf)/(xi-xf));

        return atan;
    }

    public static double getSX(double xo, double yo, double vo, double gravity, double angle, double time) {
        double dx = (xo) + vo * Math.cos(angle) * time;

        return dx;
    }

    public static double getSY(double yo, double vo, double gravity, double angle, double time) {

        double dy = (yo) + vo * (Math.sin(angle) * time) - ((gravity / 2) * (time * time));

        return dy;
    }

}

package balistica;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
*
*/
class View implements ApplicationListener, InputProcessor {

private SpriteBatch batch;
private Sprite ball;
private Sprite box;

private int boxPosX, boxPosY;
public double ballPosX, ballPosY;

private double angle;
private double frameTime;

@Override
public void create() {
    Gdx.input.setInputProcessor(this);

    ball = new Sprite(new Texture(Gdx.files.internal("ball.png")));
    box = new Sprite(new Texture(Gdx.files.internal("cTest.png")));
    batch = new SpriteBatch();

    boxPosX = 20;
    boxPosY = 20;

    ballPosX = 0;
    ballPosY = 0;

    frameTime = -1;

}

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
    if (frameTime >= 0) {
        double vo = 60;
        double xo = 20;
        double yo = 20;
        double gravity = 10;
        //getSX(double xo, double yo, double vo, double gravity, double angle, double time)
        ballPosX = Update.getSX(xo,yo,vo,gravity,angle, frameTime);
        //getSY(double yo, double vo, double gravity, double angle, double time)
        ballPosY = Update.getSY(yo,vo,gravity, angle, frameTime);

        System.out.println("x;y" + ballPosX + ";" + ballPosY + "  at  " + "FrameTime : " + frameTime);
        frameTime = frameTime + 0.1;
    }

    batch.begin();
    batch.draw(box, boxPosX, boxPosY);
    batch.draw(ball, (int) ballPosX, (int) ballPosY);
    batch.end();

}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {
}

@Override
public boolean keyDown(int keycode) {
    return true;
}

@Override
public boolean keyUp(int keycode) {
    return true;
}

@Override
public boolean keyTyped(char character) {
    return true;
}

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    angle = Update.getAngle(boxPosX, screenX, boxPosY, screenY);
    System.out.println("Box = (" + boxPosX + ";" + boxPosY + ")");
    System.out.println("Screen = (" + 200 + ";" + 200 + ")");

    System.out.println("Angle" + angle);

    frameTime = 0;
    return true;
}

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    return true;
}

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    return true;
}

@Override
public boolean mouseMoved(int screenX, int screenY) {
    return true;
}

@Override
public boolean scrolled(int amount) {
    return true;
}

}

I just noticed that im stupid.

I forgot that in libgdx the Y is from the top to bottom.

SO…

 @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        System.out.println("Screen = (" + screenX + ";" + screenY + ")");
        screenY = Math.abs(Gdx.graphics.getHeight() - screenY);
        
        System.out.println("Fix ScreenY = " + screenY);
        angle = Update.getAngle(boxPosX, screenX, boxPosY, screenY);
        System.out.println("Box = (" + boxPosX + ";" + boxPosY + ")");

        System.out.println("Angle" + angle);

        frameTime = 0;
        return true;
    }

why aren’t you using forces?
gravity force + some aerodynamic drag (just a force that pulles the arrow back, added to the plumes of the arrow)