I need some help understanding the concept. I checked Wikipedia to see their article on Projectile Motion, but it made no sense to me :/ I am wanting to use this (rather than cheating) in a Scorched Earth clone. I'm wanting to use the formula (just double checking that I know what formula I am referencing) where you give it a Velocity, a Height, and an Angle, and it will return the Distance it has traveled. My friend gave me a formula that might be close to correct, but I'm not certain: -9.8*V^2+.5(sin(A))*V+H=D. Also, how would I implement this to get the X and Y positions given a Distance? I have an idea, but I doubt it is correct.
is the angle a measure of inclination or declination?
It can be both, though I will limit it you inclination for this. It might eventually do declination if it doesn't require a completely different formula. Also, the angle is in radians.
well inclination vs declination is going to switch whether you want sin or cos. I'm not 100% sure what the extra height variable is for - are you shooting over uneven terrain?

horizontal distance traveled is cos(A)*V*(time launch->impact). What that time is going to be will depend on the terrain. For flat terrain, you need to find the zeros of: y=-(1/2)*9.8*t^2 + sin(A)*V*t.

You'll almost certainly need to actually trace the projectile through its arc though, to deal with collision issues.
If you want to stare at some TI-BASIC code that does projectile motion, feel free to glance through:

http://www.ticalc.org/archives/files/fileinfo/387/38731.html

Please bump this thread tomorrow, though; I have more intelligent contributions to add when (not(sick) || not(3:30am)).
Also: http://www.ticalc.org/archives/files/fileinfo/369/36974.html
I don't know your level of physics or math, so let me start from the basics:

First you have position. This is pretty straightforward. I'm at X position. Done.

Change in position over a length of time is called velocity. For all intents and purposes, speed, but speed only refers to the magnitude of velocity. Velocity is like speed, but also has a direction. 2 mph is speed. 2mph north is velocity. Velocity must be relative to something. For this reason, velocity can be negative or positive. In the instance of Scorched earth you have two velocities. Horizontal velocity and vertical velocity. I find that it's easiest just to use the graphing plane for your negatives and positives. That is, an object moving down has a negative vertical velocity, moving up has a positive vertical velocity. Moving right positive horizontal velocity, left, negative horizontal velocity.

Change in velocity over time is acceleration. This is the nitty gritty of basic physics. Let's say you're driving in a car going 10 meters per second, and you speed up to 20 meters per second over a period of 10 seconds. Your change in velocity is 10 meters per second (10 m/s), over a period of 10 seconds (10s), so your acceleration is change in velocity over time, so, (10m/s)/(10s) = 1 m / s^2. That is, 1 meter per second squared (It seems weird to talk about squared seconds, I know).

When we talk about Forces, we usually talk about acceleration, because given Newton's laws, Force = Mass*acceleration. Gravity is such a force. Gravity accelerates us downwards at 9.8 meters per second squared (but it's easy just to use a round 10 mps^2 for easy calculations). In the case of a calculator screen there are no such units like meters are seconds. You only have pixels, and "ticks" (every time your program loops is called a "tick." Think of a clock ticking.). I usually like to make gravity something like 1 pixel per tick squared.

Just so I know you get the hang of what I'm saying about gravity and acceleration, let me use the following example:

If you drop an object, it doesn't fall at a constant speed, it gets faster and faster and faster until it hits something. This is because gravity is accelerating (changing velocity) it. Let's talk about pixels. Lets say gravity accelerates at 1 pixel per tick^2.

An object falling from rest would have the following velocities and positions at a given tick:

tick | velocity | position

0 | 0 | 0
1 | 1 | 1
2 | 2 | 3
3 | 3 | 6
4 | 4 | 10
5 | 5 | 15

So you can see that it starts falling faster and faster and faster.

The general formula for a falling object is given by

Height = (1/2)(grav accel)(tick^2) + (initial vertical velocity)(tick) + (initial height)

In which your grav accel is a negative number (Like I said, I prefer -1 px/t^2).

Now you need to worry about firing angles. Firing angle affects your initial velocity. That equation up there only gives you the Height of your object at any given time. However, your initial vertical velocity depends on your firing angle. If you fire a gun straight up, all of the initial velocity is vertical velocity. If you fire it horizontally, there is no vertical velocity.

I hope you have a base in trigonometry or at least geometry.

We need to draw a triangle:

------/-----------
-----/-|----------
----/--|----------
-I-/---|V--------
--/----|----------
-/-----|----------
/A_H |----------

The side labeled I is your initial velocity. The side labeled V is the vertical component of this velocity, and the side labeled H is the horizontal component. A is the firing angle.

We need to extract both the vertical and horizontal components to know the projectile's position.

If you remember from geometry, sin = opposite / hypotenuse, thus sin(A) = V/I. We are trying to find V, so we multiply both sides by I giving us V = Isin(A). By the same method, we determine that H = Icos(A).

Substituting our V equation back into that height equation you have:

Height = (1/2)(grav accel)(tick^2) + (Initial Velocity*sin(A))(tick) + (initial height)

For the horizontal position (you could call this distance I guess), it is a lot simpler. Unless you really want to include wind or air resistance, there is no acceleration in the horizontal direction, so the horizontal velocity is constant. Therefore, Distance = (Initial Velocity*cos(A))(time) + (initial distance).

Those are the basics of projectile motion.
Excellent post, Pseudoprogrammer; that's more or less what I was going to tell him myself, but in about double the detail. Tanner, how does this do you for?
Reading over it, it makes a lot of sense, but I am going to try it out on my calculator first to see if I've got it Smile
_player1537 wrote:
Reading over it, it makes a lot of sense, but I am going to try it out on my calculator first to see if I've got it Smile
I'd recommend you start with a trivial program that takes the starting coordinates and velocity of the projectile and plots its motion across the screen to make sure you have the concepts, and then work it into your game from there.
Yay, I got this implemented Very Happy It was a little confusing because I was using a coordinate plane where (100,100) is in the bottom right quarter instead of the top right quarter, so my gravity was flipped. But it works now Smile Thanks greatly, Pseudo!
_player1537 wrote:
Yay, I got this implemented Very Happy It was a little confusing because I was using a coordinate plane where (100,100) is in the bottom right quarter instead of the top right quarter, so my gravity was flipped. But it works now Smile Thanks greatly, Pseudo!
That's great to hear! I had to deal with the unfortunate fact in Obliterate of the top of the screen being low Y coordinates and the bottom being high Y coordinates, thus requiring me to have inverted gravity, which threw me for a loop for a while.
Just pretend you're in Australia. It's a well known fact that gravity is upside down there.
Pseudoprogrammer wrote:
Just pretend you're in Australia. It's a well known fact that gravity is upside down there.
Obviously. Pretty much anywhere below the equator, come to think of it. Smile

While we're on the subject of gravity and projectile motion, I think that my BASIC gravitational simulators have been cool enough that an ASM gravity simulator would be (difficult but) a lot of fun.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement