What Is the Initial Velocity Formula for Projectile Motion in Game Development?

  • Thread starter Thread starter bmf59
  • Start date Start date
  • Tags Tags
    Game Projectile
AI Thread Summary
To calculate the initial velocity needed to hit a target at a specific distance without using time, the projectile motion formula can be rearranged. The key equation is v = √[gR/(sinθ cosθ)], where R is the range and θ is the launch angle. This formula allows you to determine the initial velocity based on the desired angle and distance. Understanding the trajectory concept is also beneficial for implementing the formula in game development. This approach provides a practical solution for programmers needing to incorporate physics into their projects.
bmf59
Messages
1
Reaction score
0
I'm writing a video game. For the AI i need to be able to calculate the proper initial velocity for a given angle to hit a target a certain x,y distance away. I don't want to use time in the formula. Does anyone know a formula for doing this? I found something about a "gunnery law" that looked similar to what i needed, but i couldn't find the formula. Any help would be appreciated since I'm a programmer and not much of a physics person. Thanks.
 
Physics news on Phys.org
bmf59 said:
I'm writing a video game. For the AI i need to be able to calculate the proper initial velocity for a given angle to hit a target a certain x,y distance away. I don't want to use time in the formula. Does anyone know a formula for doing this? I found something about a "gunnery law" that looked similar to what i needed, but i couldn't find the formula. Any help would be appreciated since I'm a programmer and not much of a physics person. Thanks.

If the target is at the same height as the launch, you can use:

y= vsin\theta t - \frac{1}{2}gt^2

where: t = \frac{x}{vcos\theta}

If x = R (range) and y = 0, you have:

vRtan\theta = \frac{gR^2}{v^2cos^2\theta}

v^3= \frac{gR}{tan\theta cos^2\theta}

v = \sqrt[3]{\frac{gR}{sin\theta cos\theta}}

AM
 


As a physics enthusiast, I would be happy to assist you with your question. The formula you are looking for is known as the projectile motion equation, which takes into account the initial velocity, angle of launch, and distance to the target. It is often written as x = v0*cos(theta)*t and y = v0*sin(theta)*t - 0.5*g*t^2, where x and y represent the horizontal and vertical distance traveled by the projectile, v0 is the initial velocity, theta is the angle of launch, t is the time, and g is the acceleration due to gravity.

To solve for the initial velocity, you can rearrange the equations to v0 = x/(cos(theta)*t) and v0 = (y + 0.5*g*t^2)/sin(theta)*t. You can then plug in the desired x and y distances and the angle of launch to calculate the initial velocity needed to hit the target. This method does not involve time in the formula, as requested.

I would also recommend looking into the concept of trajectory and how it relates to projectile motion, as it can help you better understand and implement the formula in your game. Best of luck with your project!
 
TL;DR Summary: I came across this question from a Sri Lankan A-level textbook. Question - An ice cube with a length of 10 cm is immersed in water at 0 °C. An observer observes the ice cube from the water, and it seems to be 7.75 cm long. If the refractive index of water is 4/3, find the height of the ice cube immersed in the water. I could not understand how the apparent height of the ice cube in the water depends on the height of the ice cube immersed in the water. Does anyone have an...
Thread 'Variable mass system : water sprayed into a moving container'
Starting with the mass considerations #m(t)# is mass of water #M_{c}# mass of container and #M(t)# mass of total system $$M(t) = M_{C} + m(t)$$ $$\Rightarrow \frac{dM(t)}{dt} = \frac{dm(t)}{dt}$$ $$P_i = Mv + u \, dm$$ $$P_f = (M + dm)(v + dv)$$ $$\Delta P = M \, dv + (v - u) \, dm$$ $$F = \frac{dP}{dt} = M \frac{dv}{dt} + (v - u) \frac{dm}{dt}$$ $$F = u \frac{dm}{dt} = \rho A u^2$$ from conservation of momentum , the cannon recoils with the same force which it applies. $$\quad \frac{dm}{dt}...
Back
Top