Projectile Motion in 3D space (Writing an Aimbot)

In summary, the conversation discusses the development of an aimbot for a popular game, specifically focusing on calculating the correct pitch angle for a bow weapon. The code provided is not functioning correctly and the individual has researched a potential solution from a Wikipedia article. However, they suspect there may be an issue with the use of degrees vs radians and a possible error in the implementation of the algorithm. The conversation concludes with the individual noting their mistake in deleting the code and planning to rewrite it. They express gratitude for any help with the issue.
  • #1
wolfknight
5
0
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.

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:
Code:
	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);
	}

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.

If anyone can help, I would appreciate it.
 
Physics news on Phys.org
  • #2
could you have a degrees vs radians issue? I noticed the last eqns using Math.atan2()

I also noticed that the wiki eqn says g*x^2 but you've used (g*x)^2 for gxsquared

Lastly, z doesn't appear to be used in the second function.
 
Last edited:
  • #3
jedishrfu said:
could you have a degrees vs radians issue? I noticed the last eqns using Math.atan2()

I also noticed that the wiki eqn says g*x^2 but you've used (g*x)^2 for gxsquared

Lastly, z doesn't appear to be used in the second function.

That might possibly be my problem. I got mad and deleted the module last night, so I'll rewrite it and try again. Thank you very much for your help!
 
  • #4
wolfknight said:
That might possibly be my problem. I got mad and deleted the module last night, so I'll rewrite it and try again. Thank you very much for your help!

Note to self: Never get mad at code and delete it instead comment it out in a more gentle deprecational mode.
 

1. What is projectile motion in 3D space?

Projectile motion in 3D space is the movement of an object in three dimensions (x, y, and z) under the influence of gravity. It is a combination of horizontal and vertical motion, where the object follows a curved path known as a parabola.

2. How does an aimbot use projectile motion in 3D space?

An aimbot uses the principles of projectile motion in 3D space to calculate the trajectory of a bullet and accurately aim at a target. It takes into account the initial velocity, acceleration due to gravity, and the position of the target to determine the correct angle and direction to fire.

3. What factors affect projectile motion in 3D space?

The factors that affect projectile motion in 3D space include the initial velocity, angle of launch, air resistance, and the acceleration due to gravity. The mass and shape of the object also play a role in determining its trajectory.

4. How can I improve the accuracy of an aimbot using projectile motion in 3D space?

To improve the accuracy of an aimbot using projectile motion in 3D space, you can adjust the initial velocity, angle of launch, and the target's position. Using more precise calculations and considering external factors such as wind and air resistance can also help improve accuracy.

5. Are there any limitations to using projectile motion in 3D space for an aimbot?

While projectile motion in 3D space is a useful tool for calculating bullet trajectory, it is not always 100% accurate. Factors such as air resistance, wind, and changes in the target's movement can affect the trajectory and lead to a missed shot. Additionally, projectile motion does not account for other obstacles in the environment, which can also impact the accuracy of an aimbot.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
Replies
2
Views
759
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
2
Views
3K
  • Introductory Physics Homework Help
2
Replies
53
Views
3K
Replies
5
Views
1K
Replies
7
Views
6K
  • Introductory Physics Homework Help
Replies
14
Views
4K
Replies
1
Views
790
  • Introductory Physics Homework Help
Replies
1
Views
1K
Back
Top