[ 15 posts ]  Reply to topicPost new topic 
Author Message
 [us]
 Post subject: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 8:33 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Question:
I want to know how much initial x speed my projectile object needs in order to hit a target object that is, d, pixels away, and the projectile object has gravity = g.

I have done this using time as a factor, but I don't want to have to use time to calculate the position of the projectile. I want to set the gravity of the projectile, then calculate the initial x speed needed to hit the target object as both, gravity and x speed are applied every frame.

Is this possible?

Thanks!

 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 9:05 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
At what angle is the projectile being fired?

 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 9:06 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
EDITED: Oops, accidental double post.

 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 9:38 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
I guess 0 degrees. Imagine the object on the top of a cliff and is only having an initial velocity in the x coordinate. So, angles don't need to be used in this scenario (luckily).

 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 10:06 pm 
User avatar
Member
[*]
You mean like throwing a projectile at a certain speed so that it goes right on top of the enemy?

 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 10:09 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
I would use a kinematic equation to find the time needed. Specifically, probably this one:

Code:
v[f] = v[i] + a * t


Solved for t, that gives us:

Code:
t = (v[f] - v[i]) / a


So if the initial vertical velocity is called "yv" and the vertical downward acceleration is called "g", you might use this:

Code:
time = 2 * yv / g


Then just multiply that by the horizontal velocity to get the distance. EDIT: Or rather, divide that from the distance to get the horizontal velocity. :)

But if your game's acceleration is nothing more than simplistic additions to velocity variables each frame (which is what Game Maker does if I'm not mistaken), that won't actually work. In that case, the only way I can think of other than hardcoding it is to use looping to simulate the trajectory. If you do have to do this, keeping a table of previously calculated distances can help with performance.

EDIT: Such a loop might look like this:

Syntax: [ Download ] [ Hide ]
Using python Syntax Highlighting
time_ = 0
y = 0
yv_prediction = yv
while y <= 0:
    y += yv_prediction
    yv_prediction += g
    time_ += 1
 


Last edited by onpon4 on Mon Mar 13, 2017 10:17 pm, edited 2 times in total.
_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Parabolic Motion Question
PostPosted: Mon Mar 13, 2017 10:16 pm 
User avatar
Member
[*]
I made a code for the Fire Nipper from SMB3, if that's what you mean.

 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Tue Mar 14, 2017 12:28 am 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
@onpon4 - Yes, that is what I did previously, and it worked. However, I was wondering if I could find the initial velocity without needing the time, I see that it's probably not possible (unless of course you simulate it as your exampled had shown). I really appreciate you taking the time to write out an explanation, by the way.

@P-Star7 - Yes, minus the actually throwing part. More like, pushing an object off a cliff.

 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Tue Mar 14, 2017 12:45 am 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
Quote:
I was wondering if I could find the initial velocity without needing the time

You mean, without even accounting for the existence of time? No, that's not possible because of really basic mathematical principles. Displacement, after all, is nothing more than a factor of time and velocity, so how could you figure out the velocity for a particular displacement without also considering the time? That would be like figuring out the volume of a glass without considering its height.

Of course some situations might enable the use of geometry too (depending on exactly what sort of arc it is), but I wouldn't see the point in that if simple equations will do. It's not like you lose anything by involving time into the equation. You could even break it down into a single equation if you really want to:

Code:
xv = xdist * g / (2 * yv)

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Tue Mar 14, 2017 10:02 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Why is y velocity in the denominator? Y velocity in the scenario I was explaining would be 0. Unless I am missing something.

 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Tue Mar 14, 2017 10:17 pm 
User avatar
C# Programmer
Member
[*]
[*]
[*]
[*]
Could you draw the scenario and include what you want to be fixed or given (ex yVel is limited to zero)?

_________________
MFGG TKO (scrapped) - Animations
Image
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Tue Mar 14, 2017 10:44 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
Quote:
Why is y velocity in the denominator?

Because you divide distance by time to get speed. The y velocity is just a part of the calculation for time.

Quote:
Y velocity in the scenario I was explaining would be 0.

Oh? So it's traveling in a straight line to the right or left?

If that's the case, then your question doesn't make any sense. If the projectile is traveling in a straight line, then any velocity in the correct direction will work. It's just a matter of how long it will take.

I agree with TheShyGuy, you should probably draw exactly what kind of movement you're talking about.

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Wed Mar 15, 2017 10:28 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
Well, I did mention it in a previous post, you must have missed it. Ok, I'll post a picture.

 
Top
Offline 
 
 
 [fi]
 Post subject: Re: Parabolic Motion Question
PostPosted: Fri Mar 17, 2017 12:53 pm 
User avatar
:3c
Member
[*]
[*]
[*]
[*]
[*]

Anyone with knowledge in physics will tell you that calculating velocity without time is kind of dumb, since
Code:
v = s/t


Then again, your question and follwing replies have been pretty confusing so I might've misunderstood your problem in the first place.

_________________
YouTube | Steam | Twitter

My signature is very empty now that I've removed the advertising. :(
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Parabolic Motion Question
PostPosted: Sun Mar 19, 2017 7:45 pm 
User avatar
D:
Member
[*]
[*]
[*]
[*]
[*]

The initial question is inadequate. What does "d" pixels away mean? You're talking about a 2D situation. D pixels away in the x-axis? Y-axis? If it's the x-axis, then you also need a height. Since you said an angle of 0°, that's basically like kicking something off a cliff to hit something below.

_________________
I support:
Image
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
 [ 15 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


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 post attachments in this forum
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group