Hi all.(adsbygoogle = window.adsbygoogle || []).push({});

I am not quite sure if this is the right forum to place this question but for me there are several forums that would fit with my situation :D

I am making a game where I have to throw/shoot a projectile through a 3 dimensional space which has to land on a specific object.

There are actually 2 similar questions that I want to ask (second one being the one with moving destination)

1) How do I calculate the Pitch of a projectile, given the Velocity, starting location(x, y, z) and targeted location (x, y, z)?

(x and y being horizontal location and z being the height.)

Well this one seems pretty simple after reading some Wikipedia pages and finding that formula.

I assume that g = 9.81 but can be modifyable in this formula... which is great.

X and Y have different meaning which I can understand because you only have to know the horizontal_distance instead of the x_distance and y_distance.

So given:

g = gravity = 9.81 (m/s)

x = horizontal_distance = √(end_location_x - start_location_x) + (end_location_y - start_location_y) (m)

z = vertical_ditstance = end_location_z - start_location_z (m)

v = initial_velocity = projectile_velocity (m/s)

But if I apply the formula with those values, I get really weird results.

I always get a value between 1.568 and 1.572 or a NaN

And yes I exacly copied that formula.

I guess that the NaN is when the projectile cannot reach the target with the given speed and gravity, but if I set gravity to 0, I sometimes get NaN values too which are impossible then.

So I messed up with the gravity (I guess)

So the question: What have I done wrong with the values?

2) This one is a bit harder.

Now I got to do the exact same thing, but now the target is MOVING!

There is one relief: the target is moving with a constant speed in a specific angle in only the X and Y axis (only hoizontal)

I talked with my friend about this one but ussually get stuff like "Why don't you just calculate the new location of the target and then apply the first formula?". And I know that they just don't understand that it is not that simple.

However one of them made a very usable statement: polling.

Just calculate the time that the projectile needs to reach the target location (without movement) and adjust the target based on that time, then do that again, and again, and again until you have a value that would be enough to make it almost perfect.

However I refuse to use that because I require the exact angle and have to be carefull with performance (we are still talking about a game)

I think that I could solve this one if I just run a few tests and compare differences, then apply factors inside the first formula to make the horizontal_distance, vertical_distance, horizontal_distance_increase and vertical_distance_increase adjust on velocity... or something similar to that.

However I have to know what I do wrong in the first one to try this thing.

But if there is anyone who can make a usefull statement of this situation, then he is welcome to share it.

I know that this might be a big thing for the first question but if it was simple... then why would I be here?

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

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

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

# Calculate the Pitch of a projectile with moving destination

Tags:

Loading...

Similar Threads - Calculate Pitch projectile | Date |
---|---|

B Calculate the expression of the antiderivative | Feb 19, 2018 |

A Numerical solution for a two dimensional 3rd order nonlinear diff. eq. | Jan 17, 2018 |

A How to calculate confluent Heun functions numerically? | Dec 25, 2017 |

A How to calculate the parabolic cylinder function D | Apr 4, 2017 |

Differential equation for projectile | Sep 3, 2014 |

**Physics Forums - The Fusion of Science and Community**