Sign in to follow this  

projectile motion

This topic is 4593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone.. i'm having some trouble coding a projectile motion.. I believe I have the projectile working correctly as the ball (Open GL) goes up and comes back down! Right so far so good... ...what i'm trying to do now is repeat the projectile when the ball touches the lower limit of my screen (i.e. 0) i've successfully coded the collision detection and thought that i had done the same for the response but its not playing properly - i reveresed the Y direction of the final velocity vector but but the projectile doesn't respond - which leads me to believe that there may be something wrong with my initial projectile motion equation... anyway after all that this is the code... (projectile motion equations) ------------------------------------------------------------------- ballVf.x(ballVi.x() * myTime); ballVf.y((ballVi.y() * myTime) - (0.5 * grav * (myTime * myTime))); ballVf is the final velocity (vector class) and ballVi is Initial velocity(again vector class)- gravity & time are floats... (this is my collision response part) ------------------------------------- if(dist < 0.0f) { ballVf.operator =(vector(ballVf.x(),-ballVf.y(),ballVf.z())); } can anyone help???

Share this post


Link to post
Share on other sites
hi!

first...you're calculating your current velocity from the initial velocity at each timestep ...that's not nice imo..

just adjust your current velocity in each timestep...
like you have a current velocity v_c and it gets updated each timestep by the influecing forces...like gravity..

at each timestep v_c = v_old + changes

in your example you have a constant acclaration...cause you multiply your initial velocity with the time passed. is that really what you want ???

that's the problem with your collision-code ...you change the velocity...but then it gets recalculated by the first formula i guess...which still uses the initial velocity...and doesn't know about the collision

hope this helps

Share this post


Link to post
Share on other sites
I am pretty sure that I know what your problem is. I would suggest modifying your equations of motion as well, but your collision problem goes like so:

You detect that dist<0.0f, and you reverse the y velocity of the ball. The next time step, the same check is done again, and it hasn't moved so it will reverse the y velocity again (thus it is now going down again, and it will get caught in an "infinite" loop so to speak). Just modify your collision detection code to something like this:


if(dist <= 0.0f)
{
ballVf.operator =(vector(ballVf.x(),-ballVf.y(),ballVf.z()));
ballVf.positionY = 0.0;
}


Make the < a <= and add the second line. That should fix the problem. I hope this was of some help.

Share this post


Link to post
Share on other sites
Hi,

thanks for getting back to me..

The equations i'm using are the actual mathematical equations of a projectile - am i right in saying that you don't use this but some hybrid version???...

I'm following the maths to the line on this program so changing things like the final velocity will push the whole program out!...

Has anyone got a small example of their projectile code?? Like i say the aim here is to repeat the bounce with constant velocities...

many thanks...

Share this post


Link to post
Share on other sites
hi!

i'm pretty sure that this equation is the actual mathematical representation of motion...but it can't handle collisions...

try to figure out what the function does...
it's a function of one parameter ...time...and it will return the current velocity of your projectile for that time... but it can't handle collisions. it will return you the typical curve a projectile will produce...

just hand the equation a time that is behind the time of collision... it will still produce a velocity downwards...and here is the problem with your collision code...it will once (when the projectile is below the ground) invert the speed..in the next timestep the projectile will be above...but again get a high speed towards the ground...

believe me...i think it's best to change your code..so it's updating the velocity in every timestep and don't recalculate it in every timestep from the input values

Share this post


Link to post
Share on other sites

This topic is 4593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this