Reputation: 1601
How would I get the initial velocity needed for a bullet to hit a target when the following are all constants
time to target
gravity
initial position of the ball and the target
radius of the ball
I am doing out a few examples in Unity 3D using c# for the code. I am not asking for the code, I just would like to know what steps to take to do this (physics wise).
Upvotes: 5
Views: 3837
Reputation: 7824
Your question can be solved using Kinematics. You need to know a few things about Physics, but it is all very simple.
Let us examine what we know:
To calculate you will need these equations:
VelocityFinal_x = VelocityInitial_x
FinalDistance_x - InitialDistance_x = VelocityInitial_x * time
VelocityFinal_y = VelocityInitial_y + gravity * time
Just rearrange the second equation to find VelocityInitial_x
Notice that we didn't need to use z-axis. Don't touch the z-axis unless the wind is moving the bullet in mid-flight.
Make sure you do these calculations once at the instant the bullet is fired, don't do it every frame of the game.
Upvotes: 6
Reputation: 1334
A nice article on Wiki regarding trajectory of projectile with detailed explanation of two-dimensional case (3D case may be easily reduced to 2D if you define a plane included start point of projectile, target point and vector of gravity).
To hit a target at range x and altitude y when fired from (0,0) and with initial speed v the required angles of launch theta are:
Upvotes: 0