• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Game Mechanics Projectile Motion application - How to choose the best trajectory ?

Hi everyone,

Firstly, I'm sorry if this problem has no place on this forum / topic.

I have a problem on a fairly physical / mechanical subject. I will first explain what I want:

I have a "projectile launcher" at (x0, y0) - in fact its more a "chick launcher" but it's not very important - the projectile being subjected to gravity, its trajectory is non-linear: it is parabolic. It is therefore projectile motion without friction things (high school things). The projectile has 2 variables : alpha then angle and v0 the initial speed. And I got my non-moving player in (x1,y1).

1596132501831.png

My question is : wich couple (x0, alpha) should I use?

I think my problem in direct cue (so (0,0) is in bottom left) and I started with that.
The coordinate equation is the following one :
1596135416090.png
So we can get vo as function of alpha:
1596137641586.png
(We can get v0 by inverting and put under the root)

So I get the "answer" of my question? Not really, there is sooooooo many couples that work and I'm strugguling on how to get a couple that works well (and finding it algorithmically since setting one of the two values is ineffective in my opinion because I want something consistent that works "well" and not have a projectile that goes super fast or super high to solve the problem. Ideally I would like him to stay in my room.)
If you have any ideas, I'm interested! And If you have any question, feel free to ask!
Thanks!
 

Attachments

Khao

Member
I'm absolute 💩💩💩💩ing trash at math but I've done this before through sheer brute force.

Instead of using formulas like a smart boy, what I did was throwing projectiles in a straight line towards their destination, with custom speed and direction values.

The speed and direction values don't actually change the X and Y positions. They change custom variables named x_pos and y_pos, which start at the objects "natural" x, y position. To move x_pos and y_pos, I use the lengthdir_x and lengthdir_y functions.

Sooo to give it the actual parabola, I had variable named "height", "height_spd" and "height_grav".

Height starts at 0.

height_spd starts at a negative value. (like -10)

height_gravstarts at a positive value, much smaller than spd. (like 0.5)

Each step I do
Code:
height+=height_spd
height_spd+=height_grav
And finally, I set the proper x and y positions to x = x_pos; y = y_pos + height. The only other thing you need to know is how many steps will pass before the height value goes back to one, so you can set your initial speed properly.

Now, this method works but is absolutely not correct and probably not what you're looking for. If you don't care, just do this and it'll work surprisingly decently. The only downside is that the projectile will always take the exact same amount of time before reaching its destination, and I would assume you'd rather have it find the shortest possible route.

So if you want to do it properly, just ignore me and wait for someone that actually paid attention at school to get the help you actually want.
 
Thanks for the answer!
Unfortunately, in fact, that's not really what I'm looking for, in my case swinging the projectile directly on the target is not really interesting ...
 

Yal

🐧 *penguin noises*
GMC Elder
Instead of using formulas like a smart boy, what I did was throwing projectiles in a straight line towards their destination, with custom speed and direction values.
I second this suggestion - the projectile actually moves in three axes (x, y, z) so it's easier to have it move straight in x/y and then simulate z movement separately... and it's relatively simple - you want to find an initial speed such that the projectile reaches its apex after half the time needed to cover the distance from the launcher to the target, given the projectile's gravity. I.e, find the zero crossing for the derivative of f = vt - gt^2 --> f' = v - 2gt --> v = 2gt... aka, the original z speed should be 2 x gravity x time needed to cover the x/y distance.
 
I second this suggestion - the projectile actually moves in three axes (x, y, z) so it's easier to have it move straight in x/y and then simulate z movement separately... and it's relatively simple - you want to find an initial speed such that the projectile reaches its apex after half the time needed to cover the distance from the launcher to the target, given the projectile's gravity. I.e, find the zero crossing for the derivative of f = vt - gt^2 --> f' = v - 2gt --> v = 2gt... aka, the original z speed should be 2 x gravity x time needed to cover the x/y distance.
Hey! Thanks for answer!
Your idea intrigues me, I don't have any issue to move my projectile straight x/y but I don't understand how I use this "z" value... Since this variable is not an internal variable, how should it modify the behavior of my game?
I created a z variable, and I add to this 2*g*time_needed (time_needed is spd*point_distance(x0,y0,x1,y1)) and now how I am supposed to use it?
Thanks!

PS : I don't use internal "gravity" and "speed" varaibles of game maker because when I learned how to use game maker, it was generally "accepted" in the tutorials that these internal variables should not be used. Should I review my basics and use them for this problem
 

rytan451

Member
Draw the projectile above its actual position. So, if its 3d position is (100, 200, 300), draw it at (100, -100). You might wish to draw trajectories flatter. This can be achieved in two ways: either reduce gravity, or multiply the z coordinate by a fixed constant before using it to modify the drawn y coordinate.

You might also want to draw a shadow of the projectile, or indicate its position in order to give a better illusion of 3D space.
 

Yal

🐧 *penguin noises*
GMC Elder
Your idea intrigues me, I don't have any issue to move my projectile straight x/y but I don't understand how I use this "z" value... Since this variable is not an internal variable, how should it modify the behavior of my game?
I created a z variable, and I add to this 2*g*time_needed (time_needed is spd*point_distance(x0,y0,x1,y1)) and now how I am supposed to use it?
Draw the projectile's sprite at x, y - z instead of the default x,y, and it'll be shifted upwards based on its z position. (Assuming Z is positive upwards - use y + z if you prefer having z negative upwards just like GM's y axis)
 

MeBoingus

Member
If you're using collision checking on the projectile (and especially if you plan to have other things move on your artificial z-axis) then you'll need to either:
Define a 'height' for each object, and check if the missile's z value is <= to the object's height.
OR if you plan on everything being at 0 on the z-axis, simply check if the missle's z value is 0 before detecting the collision.
 
Top