Projectile Math
by Johannes Pauw · in Torque Game Builder · 02/24/2006 (3:05 pm) · 4 replies
I'm wondering if anyone has any idea of the math I could use to calculate the impulse force needed to fire an object between two points when it has gravity acting on it? Essentially, I have a game where the player can fire toward any point on the screen from where the player currently is (using the mouse), but the projectiles are affected by gravity and don't move very fast. I'm wondering how to calculate the impulse force needed to exactly reach the point I want to shoot at.
Many Thanks,
Johannes Pauw
Many Thanks,
Johannes Pauw
About the author
Recent Threads
#2
My suggestion Johannes is to use a trial-and-error method to derive the formula you're looking for. Test the firing of projectiles at various angles and with various impulse forces. Take note of where they land. Eventually you should have a graph that displays a straight line, or probably a curve. From that you can probably derive a means to approximate the results from the original inputs.
03/03/2006 (4:50 am)
As far as I know T2D's built-in physics won't help you predict your parabolas.My suggestion Johannes is to use a trial-and-error method to derive the formula you're looking for. Test the firing of projectiles at various angles and with various impulse forces. Take note of where they land. Eventually you should have a graph that displays a straight line, or probably a curve. From that you can probably derive a means to approximate the results from the original inputs.
#3
^ plenty of good primers that show you the math around on the web. I dont have time to pull together the exact equation you need right now. But you should be able to solve the projectile motion equations fairly easily in script to get you a V(0) value to use. You can then apply a polar velocity to the projectile to match that V(0) and land your shots where your mouse is pointing.
03/03/2006 (8:41 am)
www.phys.ttu.edu/~rirlc/Lecture6.html^ plenty of good primers that show you the math around on the web. I dont have time to pull together the exact equation you need right now. But you should be able to solve the projectile motion equations fairly easily in script to get you a V(0) value to use. You can then apply a polar velocity to the projectile to match that V(0) and land your shots where your mouse is pointing.
#4
My apologies if this isn't the sort of thing you are thinking of.
03/05/2006 (3:07 pm)
I answered a similar question (i think the same?) in a thread earlier at http://www.garagegames.com/mg/forums/result.thread.php?qt=39664My apologies if this isn't the sort of thing you are thinking of.
//Returns the velocity at this angle to hit the target with given input
//Returns -1 if there is no solutions
function findVelGivenAngle(%toTargetX, %toTargetY, %angle, %accel)
{
%angle = mDegToRad(%angle);
if(2/%accel*(%toTargetY+%toTargetX/mtan(%angle)) < 0)
return -1;
%val = (%toTargetX/msin(%angle) / msqrt(2/%accel*(%toTargetY+%toTargetX/mtan(%angle))));
return %val;
}
//Returns the angle from 0 to 360 from the vertical to hit a target with given input
//Returns -1 if there is no solution given the inputs
function findAngleGivenVel(%toTargetX, %toTargetY, %vel, %accel)
{
%angle = mDegToRad(%angle);
%A = %accel*%accel*1/4;
%B = -%toTargetY*%accel-%vel*%vel;
%C = %toTargetX * %toTargetX + %toTargetY*%toTargetY;
%QuadSol = (-%B - mSqrt(%B*%B - 4*%A*%C))/2/%A;
if(%QuadSol < 0)
{
%QuadSol = (-%B + mSqrt(%B*%B - 4*%A*%C))/2/%A;
if(%QuadSol < 0)
return -1;
}
if((1/2*%accel*%QuadSol-%toTargetY)/%vel/msqrt(%quadSol) > 0)
%sol = (mASin(%toTargetX/%vel/msqrt(%QuadSol)));
else
%sol = (mDegToRad(180)-mASin(%toTargetX/%vel/msqrt(%QuadSol)));
if(%sol < 0)
return (mRadToDeg(%sol)+360);
else
return mRadToDeg(%sol);
}
Associate Anthony Rosenbaum