How to find initial velocity with fixed angle of projectile

Started by
12 comments, last by TiagoKo 12 years, 11 months ago
Hello guys im new here.

Im making a game like gunbound or worms, and i need help to make computer hit the target with wind force.

My plan is to use a fixed angle, and to find initial velocity to launch the projectile.

I found this equation but it works without wind: Image3.gif

'L' = distance X from the target and 'h'=distance Y

Anyone know similar equation that works with wind force?

Sry my english.
Advertisement
It depends on how exactly you have implemented your "wind force".
I implemented wind like acceleration X and Y every frame i increment on velocity X and Y.

I implemented wind like acceleration X and Y every frame i increment on velocity X and Y.


That just has the same effect as gravity, then. You can just add the two together, define "down" to be the direction in which that vector points and use the same formula you would have used without wind.

Let me point out that your wind will probably feel wrong, because that's not at all what wind does to things. A better model would have drag, and the wind is used at the point where you compute the velocity of your object with respect to the air. If the drag is linear, you can still solve the resulting differential equations analytically and get a closed formula. But perhaps you should start thinking about numerical methods that are much more flexible.
Here's something along the lines of what alvaro is suggesting (in terms of a better model)...

Your projective has state (x,v), where x is its position vector and v is its velocity vector. Letting m be its mass, c a drag coefficient, and u(x) the wind velocity at position x, a reasonable model is,

dx/dt = v
dv/dt = (1/m)*(m g + c ||u(x)-v||(u(x) - v)) .

which I will write compactly as,

dx/dt = v
dv/dt = f(x,v) .

A simple and effective way to integrate this is to choose a fixed timestep dt and run,

x[sub]k+1[/sub] = x[sub]k[/sub] + v[sub]k[/sub] dt
v[sub]k+1[/sub] = v[sub]k[/sub] + f(v[sub]k[/sub], x[sub]k+1[/sub]) dt

which is the Symplectic Euler method.

[quote name='Zrymer' timestamp='1305048516' post='4809039']
I implemented wind like acceleration X and Y every frame i increment on velocity X and Y.


That just has the same effect as gravity, then. You can just add the two together, define "down" to be the direction in which that vector points and use the same formula you would have used without wind.

Let me point out that your wind will probably feel wrong, because that's not at all what wind does to things. A better model would have drag, and the wind is used at the point where you compute the velocity of your object with respect to the air. If the drag is linear, you can still solve the resulting differential equations analytically and get a closed formula. But perhaps you should start thinking about numerical methods that are much more flexible.
[/quote]

Ok with wind accelaration Y i can sum with gravity acceleration, but about acceleration X i dont know what to do.


Acceleration is a vector. Add gravity and wind to find the total acceleration. Now you can change coordinates so the acceleration's direction is "down" and you can use whatever formula worked before you had wind.
Change the acceleration direction to "down"..... it dont make sense. its only make gravity acceleration bigger.
Or just use an iterative solver: guess the result then check if it's valid (the distance of the desired point and the calculated point is smaller than a small value), if not: refine the guess.

It would be easier for us to help if you showed how you calculate the position from the angle and the velocity (which is a fishy term anyway. Velocity is a vector, so the angle is redundant here. I guess you meant speed, which is the length of the velocity vector.)

Or just use an iterative solver: guess the result then check if it's valid (the distance of the desired point and the calculated point is smaller than a small value), if not: refine the guess.

It would be easier for us to help if you showed how you calculate the position from the angle and the velocity (which is a fishy term anyway. Velocity is a vector, so the angle is redundant here. I guess you meant speed, which is the length of the velocity vector.)


Exactly, the equation that i got is to find speed, and i use cos and sin to get vector from speed.
I will try to find any formula that work directly with vectors, i guess it will be easier than work with angles.

This topic is closed to new replies.

Advertisement