Alright, so, I am writing an aimbot for a popular game, and I need a bit of help with calculating the correct pitch angle for the player. The weapon is a bow, so the arrows are affected by gravity. I am trying to find the pitch angle that accounts for gravity and distance from the Entity you are firing at.(adsbygoogle = window.adsbygoogle || []).push({});

My current code doesn't work, but I will post it anyways. I have researched the correct algorithm (I found it at http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_required_to_hit_coordinate_.28x.2Cy.29) and have attempted to implement it. However, when the aimbot is being used, for some reason, it stays in the middle of my screen, regardless of the entity's Y value or the player's Y value. I have the velocity correct, and the gravity constant correct, and that is all I know.

Anyways, enough rambling, here is my code:

The gravity constant is -0.05D, and the velocity doesn't matter, as I have compared it to the in-game arrow velocity and it matches.Code (Text):

private float getBowPitchFromEntity(Entity e) {

double x = getX(e);

double y = getY(e);

double z = getZ(e);

double velocity = getVelocity();

double posX = Math.pow(x, 2) + Math.pow(z, 2);

double height = y - getY(getPlayer());

return (float)getTrajectory(posX, z, velocity, height);

}

private double getTrajectory(double x, double z, double velocity, double height) {

double vsquared = Math.pow(velocity, 2);

double vquad = Math.pow(velocity, 4);

double gxsquared = Math.pow(x * gravityConstant, 2);

double gx = x * gravityConstant;

double twoyvsquared = 2 * Math.pow(height * velocity, 2);

double add = Math.atan2(vsquared + Math.sqrt(vquad - (gravityConstant * (gxsquared + twoyvsquared))), gx);

double sub = Math.atan2(vsquared - Math.sqrt(vquad - (gravityConstant * (gxsquared + twoyvsquared))), gx);

return Math.min(add, sub);

}

If anyone can help, I would appreciate it.

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Projectile Motion in 3D space (Writing an Aimbot)

**Physics Forums | Science Articles, Homework Help, Discussion**