Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I go about predicting where an object would land?

Asked by 6 years ago

A prime example of this is in HHCB 9v9. Any tips?

Also, I generally use bodyvelocity but if there's a way to do this differently feel free to give out ideas.

1 answer

Log in to vote
1
Answered by
fredfishy 833 Moderation Voter
6 years ago
Edited 6 years ago

There are equations you can plug in to get values for, and I'm sure you could find them with a Google search for "Trajectory equations" or something. However, what's really going on in them is the application of a set of equations called "SUVAT equations". At least that's what they were called when I was taught them, ymmv.

SUVAT equations involve 5 different variables arranged in a variety of ways. They govern "particles", which basically means that we assume the thing moving is infinitely small. It turns out this is generally an alright assumption to make, because usually an object will move a lot further than its own dimensions.

S - Weirdly, this is "displacement", or in more normal terms, "distance". U - This is the initial velocity of the object. Chosen because it looks a lot like a v for velocity. V - This is the final velocity of the object. A - This is the constant acceleration that the object undergoes while in motion. The "constant" part is important. If the acceleration is going to change, SUVAT equations can't be used. Since "acceleration" here refers to a vector, this means acceleration can't increase, decrease, or change direction. T - Finally, time. This refers to how long the object took to move a distance of s from its initial position.

Ok, but how do these variables help us? They help us because there are a series of equations we can plug values in to and re-arrange. Typically, you work out which three variables you have, which one you need, and which one you don't care about.

The first equation is s = u * t + (1/2) * a * (t ^ 2). This is a bit of a nasty equation, because solving it can often result in two equally correct answers thanks to the square operation. The derivation for it basically involves some calculus, and is beyond the scope of this explanation. However, we can probably recognise s=ut as speed = distance × time as something we're already familiar with.

It's probably the worst equation here, so if you can get away with using a different one, that's probably best. Sometimes you can't avoid it though.

The second equation is s = t * (u + v) / 2. This is sort of intuitive when you think about it. Normally, we think of speed = distance × time. If we know we've got a start speed and an end speed, and we know that the rate of change (acceleration) between the two speeds is constant (which we know because otherwise we wouldn't be using SUVAT) taking the average of both speeds and applying it like we would speed = distance × time just sort of make sense.

Third, we've got v^2 = u^2 + 2*a*s. Another nasty one. I don't really have any intuition to help you remember this one, so you'll either have to learn it, or look it up every time.

Finally, we've got v = u + a*t. This is another one that just sort of makes sense. The final speed is the speed we start at, together with the speed we gained (the at part).

NB - If you're particularly eagle eyed, you might have noticed that we're missing an equation that involves v but not u. What if we need one? Well we can sort of be a bit sneaky. If we think of things in reverse, we can replace the u with v in s=ut+0.5at^2, as long as we take the negative of acceleration. Let me know if this doesn't make sense and I'll try to explain it a bit better.

Okay, but how do we actually use these equations? We'll go through an example to derive a fairly standard equation you can probably find online.

Step 1, break vector down into component parts

You've probably noticed that we haven't used any angles in our equations. This is probably contrary to what you had in mind, but bare with me. Suvat equations only deal with motion specifically in one dimension. However, this isn't actually as much of a problem as it first seems.

The way you most likely have speed at the moment is as a velocity vector. Like all vectors, velocity has a direction (where the speed is going) and a magntiude (how speedy the speed is). If we say that a car is going 300 m/s, then that's a pretty fast speed for a car. If we say that a car is going 300 m/s right, then we now have a pretty fast velocity for a car.

The reason I'm sort of labouring on this point is that any vector can be decomposed into component parts. This sounds mathsy, but is actually really simple when you think about it.

Imagine we know we want to throw something at 10m/s, at an angle of 30 degrees. We can think of this as a triangle (I know in the diagram it's 53.1, but 30 degrees makes the maths much easier). If you've done trigonometry, you'll know that we can use SOH-CAH-TOA to pretty easily find the lengths of a and b. What's important here though is that a is a velocity for the x axis, and b is a velocity for the y axis.

We can basically solve two different equations, one for x and one for y, and then combine the result at the end to get the answer for our problem.

In this example, the vertical component of our 10m/s velocity is given by sin 30 = b / 10, which we rearrange to get 10sin30, which we calculate as 5. Ignoring horizontal motion, our projectile is moving 5 m/s upwards.

The horizontal component is 10cos30, which we calculate as 5sqrt(3).

For the sake of generality, we'll use Vsin? and Vcos? for vertical and horizontal components, respectively (V is our known initial velocity along the hypotenuse).

Step 2, work out the "hang time" of our object

We need to work out how long our object is in the air. To do this, we can use v = u + at, and work out when the object first stops. This point is half way through its flight, so if we work out t and double it, we'll get our answer for "hang time".

Since we know that v = 0, we can basically just ignore it, and rearrange to get -u / a = t. There's a negative in this equation, and this is where the distinction between vectors and magnitudes becomes important. Obviously, we can't get a negative time, but we don't, because initial speed is in the opposite direction to acceleration.

Obviously, initial speed is upwards, and acceleration (gravity) is downwards. This means that they have different signs, and the negatives basically end up cancelling out.

Doubling this, we get -2u / a as the total time our object is in the air. Since we're dealing with the vertical component here, we know that u = Vsin?.

t = -2Vsin? / a

Step 3, work out how far we travel horizontally in that time

We can use s = ut + 1/2 at^2 here, but don't panic. Because we're only looking at horizontal motion, we don't actually get any faster or slower for the duration of flight. This means that a = 0, and we can totally ignore 1/2 at^2.

This leaves us with the familiar s = ut, which we don't even need to re-arrange to get what we want.

First, we plug in u = Vcos? to get s = Vcos? * t.

Next, we plug in t = -2Vsin? / a to get s = Vcos? * -2Vsin? / a. With a little re-arranging to make the next step easier, this is s = -Va * (2 sin ? cos ?).

Step 4, apply some trigonometry magic

I don't know how much trig you've done, so the next step might seem a little weird, but you'll just have to trust me.

In trigonometry, it's a fact that 2 sin ? cos ? = sin 2?. No matter what numbers we put in for ?, both sides of the equation will always be the same.

Why do we care? We can use this to simplify our equation.

s = -Va * sin 2?

Since we derived this properly, we know that V and a are in opposite directions. Once we properly understand this and are aware that we need to be careful, we can ignore the negative and we get

s = Va * sin 2?

In ROBLOX, acceleration downwards is 196.2, so that's the value you'd want to use there.

This is obviously just one example of what we can do with SUVAT equations. If you've read through this properly and really understood it, with the exception of that trigonometric identity, you should be able to derive basically anything you'd want.

The Wikipedia article on projectile motion has some nice derivations you can follow along with as well.

Leave a comment if you'd like me to try and go through a derivation for a specific scenario.

0
I had formatted this nicely with thetas instead of ?, but apparently scriptinghelpers hates me. fredfishy 833 — 6y
Ad

Answer this question