
I need a formula to find x depending on the distance of the player from the gun.
X is the angle at which the guns turret is pointed.
The projectile will then arc and land on its target.
Does anyone have the knowledge or the formula to do this?
Posted 02 January 2012 - 04:27 PM

Posted 02 January 2012 - 04:56 PM
Posted 02 January 2012 - 09:16 PM

Posted 02 January 2012 - 09:49 PM
Edited by peter henry, 02 January 2012 - 09:54 PM.
Posted 03 January 2012 - 12:21 AM
Really? If it seems easier you could even use cos2 2x + sin2 2x = 1 to make it an equation for cosine or sine, squaring out the root and solving the quadratic that results.I've even run into college professors that don't know that this equation can be solved
Posted 03 January 2012 - 01:03 AM
My example:
http://dl.dropbox.co..._velocidade.gmk
Or:
sen2a=g*dist/sqr(spd);
if abs(sen2a)>1 exit;
ang=radtodeg(arcsin(sen2a))/2;
obj=instance_create(x,y,obj_projectile);
obj.gravity=1;
obj.direction=ang;
obj.speed=spd;
Edited by peter henry, 03 January 2012 - 01:04 AM.
Posted 23 February 2012 - 04:01 AM
Posted 16 April 2012 - 06:04 PM
If the ball is projected with a speed of u, making an angle A with the horizontal, in a gravitational field of strength g ....
Then the only force on the ball will be gravity...
This will cause the ball to have an acceleration of g vertically downwards, We will take upwards as positive so the acceleration is -g.
Acceleration is the rate of change of velocity...
So by integrating the acceleration with respect to time, t , we will get a value for the vertical componant of velocity Vy:
Vy = -gt + c. (Eq 1)
The vertical component of the initial velocity will be uSin(A), by simple trig...
So when t = 0, Vy = uSin(A).
Therefore, plugging those values into (Eq 1), we get:
c = uSin(A)..
So the general equation for Vy is:
Vy = -gt + uSin(A). (Eq 2)
Now velocity is the rate of change of displacement...
So by integrating the vertical component of velocity (Eq 2) with respect to time, we will get a value for the vertical displacement y:
y = (-gt2)/2 + utSin(A) + k. (Eq 3)
When t = 0, y = 0, i.e at ground level, so subbing these values into (Eq 3) gives us:
k = 0.
So the general equation for y is:
y = (-gt2)/2 + utSin(A). (Eq 4)
Now we want the to find out how long it will take for the ball to reach the ground, so we set y = 0...
This will give us two values for t, one will be at the initial point of projection (i.e. t = 0) and the other will be the time we want.
So:
0 = (-gt2)/2 + utSin(A).
We can factorize out a t and get:
0 = t( (-gt)/2 + uSin(A) )
This tells us either t = 0 or:
(-gt)/2 + uSin(A) = 0
Solving this gives us:
t = 2uSin(A)/g. (Eq 5)
Now we know how long it will take for the ball to reach the floor again...
Because we know there is no forces acting horizontally, the ball will move with a constant horizontal component of velocity, uCos(A)... (simple trig again)
This means that we can use speed = distance / time, to calculate the horizontal distance that will be traveled, x.
uCos(A) = x/t
So x = utCos(A) (Eq 6)
We know the time that will have elapsed before the ball hits the floor from (Eq 5)...
So subbing t from (Eq 5) into (Eq 6) gives us:
x = 2u2Sin(A)Cos(A)/g. (Eq 7)
All we have to do now is solve this equation for A, and that is your angle...
and as Sin(2A) = 2Sin(A)Cos(A).
x = u2Sin(2A)/g.
So, Sin(2A) = xg/u2.
And, 2A = Sin-1(xg/u2).
Therefore:
A = Sin-1(xg/u2)/2.
Edited by ga05as, 16 April 2012 - 06:09 PM.
Posted 17 April 2012 - 09:30 PM
degtorad((.5(arcsin(g*R)/(V^2))))
90-(degtorad((.5(arcsin(g*R)/(V^2))))
180-(degtorad((.5(arcsin(g*R)/(V^2)))).
Edited by dmahurdle, 17 April 2012 - 09:32 PM.
0 members, 0 guests, 0 anonymous users