AlanF
AlanF

Reputation: 1601

Calculate the initial velocity needed for a ball to hit a target

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

Answers (2)

axwcode
axwcode

Reputation: 7824

Your question can be solved using Kinematics. You need to know a few things about Physics, but it is all very simple.

  1. When the bullet is fired the only force acting on the bullet is gravity.
  2. Acceleration on the x-axis will be 0.
  3. Acceleration on the y-axis will be gravity.

Let us examine what we know:

  • time
  • gravity
  • distance_to_target

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

game development germ
game development germ

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).

enter image description here

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:

enter image description here

Upvotes: 0

Related Questions