I am working on a new game written using LibGdx Engine and Java. I have a problem with some physicists in this game.
I want to shoot an arrow in a ballistic trajectory (angry bird style) and cannot find an equation for this.
I use these speed equations:
float velx = (float) (Math.cos(rotation) * spd);
float vely = (float) (Math.sin(rotation) * spd);
I add this to the current position, and the arrow shoots in one direction - straight.
I thought that perhaps changing the rotation would help me achieve what I want (ballistic path).
It helps, but I also want to have a trajectory.
I saw this ProjectileEquation Class, which I already published, but did not know how to work with it:
public class ProjectileEquation
{
public float gravity;
public Vector2 startVelocity = new Vector2();
public Vector2 startPoint = new Vector2();
public Vector2 gravityVec = new Vector2(0,-10f);
public float getX(float n) {
return startVelocity.x * (n ) + startPoint.x;
}
public float getY(float n) {
float t = n;
return 0.5f * gravity * t * t + startVelocity.y * t + startPoint.y;
}
}
I am looking for some help to help me use this class for ballistic trajectories.
This is how I tried to use it:
for(int i =0;i<30;i++)
{
Texture f = ResData.Square_1;
ProjectileEquation e= new ProjectileEquation();
e.gravity = 1;
e.startPoint = new Vector2(bow.getX(),bow.getY());
e.startVelocity = getVelocityOf(bow.getRotation());
Vector3 touchpos = new Vector3();
s.draw(f,e.getX(i) ,e.getX(i),5,5);
}