Recommended Posts

Hello everyone!
Here goes a physics question for you peoples.
Based on fire power and angle of the gun shooting, how can I trace a smooth path for the bullet to travel?
Easy? Hard? In the middle? Thanks!

Share this post

Link to post

Share on other sites

Original post by Leo28CI don't wanna sound like a complete noob, but isn't there something easier than that? I don't understand most of the symbols and variables and stuff...

Right, which is why "the symbols and variables and stuff" are explained in the article. Now if you actually have a specific question about the article and/or implementation, we'd love to help, but unfortunately there is no magic solution.

However the bullet goes blazing fast to the top of the screen and my program crashes. I can't even see the bullet; I put a sleep(1000) at the end of that code and it increased by, say, 75 pixels per go...

I'm pretty sure I copied the formula right. Except;

1. Is 'v' the power of the launch?2. Do I have to update 'yo' after each go, or does it stay at the position of the gun?3. How do I do 'd'?

Share this post

Link to post

Share on other sites

Original post by Leo28CI'm pretty sure I copied the formula right. Except;

1. Is 'v' the power of the launch?2. Do I have to update 'yo' after each go, or does it stay at the position of the gun?3. How do I do 'd'?

I don't get in what order I do everything neither.

Thanks all for helping me with this!

The wikipedia article is poorly written, so don't feel bad if you find it confusing. The formula you are using will work, but your implementation has some errors. First, to answer your questions:1. v is the initial speed of the bullet. Its value never changes.2. y0 is the initial height of the bullet. Its value never changes.3. d is the distance the bullet has traveled. It is the same as your bullet.x, but it is not used in the equation you are using so don't worry about it.

Now, the problems in your code:First, 'v' is initial speed of the bullet, its value is not supposed to change. The good news is this will simplify your code.Second, make sure your angles are in the correct units. A common mistake is to use degrees when you should be using radians.

Now here is the bad news.9.81 is the acceleration due to gravity in terms of meters and seconds, but you are using different units -- pixels and frames. Since you are not using meters and seconds as your units, 9.81 is not the right value for 'g' and you must figure out what the right value is. In order to get the value right, you need to figure out the conversions between pixels and meters and seconds and frames.

A better idea would to change over to using meters and seconds, but that might be a lot of work. A quicker way to get it working would be to simply adjust the 9.81 to a different value until the path looks the way you want it to look. With the angle set to 45°, try starting with 'g' = 0.01 instead of 9.81, and adjust it until path looks good.

Edit: Forgot something

In your code, "bullet.x = bullet.x + 1" means that the speed of the bullet in the X direction is 1 pixel per frame. The initial speed of the bullet is then: