Crazy how the exact problem I have been banging my head against the wall trying to solve for the past couple days was in a Sebastian video the whole time. Incredible stuff!
This is probably one of the coolest ways to visualize and learn the use of the kinematic equations while studying math in school. Love this series and looking forward to more.
Ah, finally! I tried to use this to create a bomb-like weapon that fires in an arc last month, but I couldn't get it working, even though I had Physics in high school and wasn't too bad at it. Damn, I forgot a lot of the essential equations. It's all coming back to me now. I even managed to solve the question at the beginning of the video before continuing. Also, the debug path thing is bound to be useful. Thanks for the video, Sebastian!
@@mangomanlassi7779 I’m late, but I’d say physics is pretty useful in helping you understand a lot about things like kinematic equation as seen here but also to other things that will help you with realistic object collisions, etc
Thank you so much for this, the AI couldn't just help me with creating an equation that would work, but this not only teach me a lot of stuff but helped me solve my problem, thanks a lot!
I adjusted your code to calculate where the ball will land if the target were moving at a constant speed. Thanks to you, I actually completed my project!
Holy shit, I've been searching for this kind of thing for so much time now and it turns Sebastian had such an awesome tutorial for this, this whole time!
Thanks for doing this tutorial. It would be cool to see how it works with a moving object. I think I can figure it out given this foundation, but you are the king and your tutorial would probably show me things I'm missing. Good job!
Just a heads up... if you set the Gravity to -60 ish, then the ball misses the target. Any idea why? rigidbody.velocity assign attempt for 'Ball' is not valid. Input velocity is { NaN, NaN, NaN }. UnityEngine.Rigidbody:set_velocity(Vector3)
omg i was going to suggest this as a video i thought would really suit your channel and I happened to be having some problems with it, just happened to glance through your videos and BOOM, thanks!
Hi, You and Your solution are awesome ;) There is one small improvement that can be made, at least to Your code on github. I would call Mathf.Abs() on every math inside MAthf.Sqrt() and than it can also work if target is lower than ball :) Thanks again for this great video.
hey man , could you please do your change to code. obviously there is an issue with current one.whenever i move the target object and the curve is about to become a straight line the curve will be disappear and everything mess up ):
You are amazing! Your videos solve so many my problems during game developer work... i so love you! THANK YOU SO MUCH! I really try boost up my mathematics skills but some tasks is really difficult.... you are great...
Vector3 DisplacementZ = new Vector3(0f, 0f, Target.transform.position.z - Ball.transform.position.z); Vector3 velocityZ = DisplacementZ/ (Mathf.Sqrt(-2 * height / Gravity) + Mathf.Sqrt(2 * (DisplacementY - height) / Gravity)); add these 2 lines of code and works in 3d, i mean when u move the object left and right
How would you go about using these equations to calculate the impact point of a thrown object? Every example I've seen predetermines the final position, but I want to know the landing point, given the initial velocity.
Lovely tutorial. Except you didn't had to drive a formula for initial velocity for horizontal. You can directly use V = d/t and that's what your derivation ends up at.
due thank you so much for making this. i was tryna implement somethig like this into my recroom game and i was having a brain aneurysm tring to put the equations in. Instant Like and sub
Great video, I played around with it a bit. If I assume the ball is a soccer ball and add a reasonable drag coefficient(Cd) on the ball, say 0.25 - then the ball stops about half way. Is it possible to modify these equations to take into account the Cd ? Does anybody know how I might be able to do this ? (edit) The equations Sebastian provides is for 'high school' physics. When you add a drag coefficient onto your ball then the formulas don't work anymore. This is bc of air resistance (drag). There is an eq for air resistance but it is not a one time formula, you need to keep applying it per frame. Hence you cannot predict exactly where the ball will land. You can use integrals to get a fairly accurate path but in Unity it is not 100% accurate.
i think i saw one video where you show some of the games you made through the years, and there was a game i would like to know how to make it, its like a mouse cursor dodger, where you need to try click a moving target on the screen, the target will move around and away from your mouse cursor on a precise way, dodging your cursors velocity maybe...? it didnt look like randomly moving cause that would obviously make the dodger fail by walking into your cursor x y position... i didnt find it again, can you tell me about it?
If the ball is missing the center of the hoop by 0.5 to 1 unit, this *might* help: I haven't watched the full video, but I asked about this for the first video (Mario jumping) on the Unity forum, and while I didn't understand the full explanation, apparently it has to do with Unity using semi-Euler approach to physics and not calculating the velocity based on the first physics frame but the second instead (or something like that). Try adding "... + (0.5 * Time.fixedDeltaTime * (whatever your acceleration is, the gravity) * -1) * Vector(dot)one" to the initial Rigidbody2D velocity and see if that helps.
This is the most thorough explanation of the subject I've seen so far. One question regarding the for loop when drawing the line: Is it a valid way for an AI to check if he can jump on a point (and not hitting the ceiling e.g.) or is there another way of doing it?
Hi Sebastian , I'm making a space exploration game in unity and the planet terrain has been stumping me for a while now and I was wondering if you could possibly help me at all or make a procedural planet series?
Probably because he wants to put that value. As a programmer you can make your own Physics engine and that includes switching the real values for values you want. If you write the code in the video and change the gravity default value for -9.81 you will have a good result using real values.
For those want to change the velocity to get to the target, you can simply increase the gravity apply to the launch object. I am using this method in my 2D project and I don't want to change the whole Physics2D setting. So I make Rigidbody2D.gravityScale = gravity(in this video) / Physics2D.gravity.y;
Looking to create a script where a game object moves in a parabola from point A to point B , unlike this video where physics works, I just need it the game object to travel between those points, any help on that ?
Old but very nice tutorial, however, I can't figure out why you have taken the gravity as -18 m/s2 instead of -9,81 m/s2 as it is supposed to be. This deviated the simulation 1.4 times off of the reality.
Does anyone know how I would be able to implement a projectile-motion-like approach to this ? I have a very similar situation, but with a cannon, so the cannon's rotation needs to influence both the x and y velocities. I have already tried implementing the cos(angle) for the x speed and sin(angle) for the y speed, but it didn't work 100%...
Maybe someone solved this problem already but I cannot stick my head around it. I copied the code exactly as written in this tutorial but the center of my ball seems to miss the center of the target by about 0.5 on the x-axis. The calculated velocity is the same and I positioned all my gameobjects as in this scene... Anyone having an idea about this weird behaviour? I tried to watch this video in slow motion but I just cannot see wether the ball trajectory would hit the targets center given the colliders would be inactive.
so question. I wanted to get this equation to work in a unity project, but I am wanting to use it with a grenade, so I place an empty object in front of the player, and that is the endpoint and the player is the start point. I can not figure out how to convert it tho, any ideas?
I think you'd need to pick a height, since an arrow can be shot in a curve between two points in a number of different angles, even in a straight line. If it were three points then you could use the middle one as the height
how to calculate the wind (x-only), for this formula: VelocityX = DisplacementX / (Mathf.Sqrt (-2 * h / gravity.y) + Mathf.Sqrt (2 * (DisplacementY-h) /gravity.y)); ? Who knows?
Hey Sebastian, awesome tutorial, I've been tinkering with this problem for a while now, you really helped me out, but I've one question, could you explain how I could apply this to a moving target?
I'm not sure whether you understood the purpose of this video. The ball's speed is actually being calculated in script so it always hits the target. Setting/adjusting the speed of the ball is easy.
Hi, I found a solution to some extent. You can decrease the gravity value to -40 for a quick ball and increase it to -5 for a really slow ball. This is not the best solution, but it works as long as you don't change the values too much.
I know this is an old video but how would you dynamically change the height of the arc based on the distance you are throwing it rather than have it as a set value?
The rate of fall is a constant irregardless of the forward velocity of the ball. So to get the ball to hit a fixed target simply make the arc shallower. e.g if target is at 9, make the highest point of the arc, H, 9.0001
If you increase the gravity, the speed will be faster to compensate. If you decrease H (peak height) then the ball will be more direct and will have to go faster to counter gravity. But outside these constraints, going faster just means you miss the target in a purely physical simulation. One option is that instead of a Rigid body you could use this math to create an animation and you can play that animation at any speed you like.
This is what I call a SIMPLE, CLEAR AND STRAIGHT TO THE POINT tutorial. Brilliant and crystal clear!
You deserve to be in one of those "People are awesome" sort of videos
Crazy how the exact problem I have been banging my head against the wall trying to solve for the past couple days was in a Sebastian video the whole time. Incredible stuff!
This is probably one of the coolest ways to visualize and learn the use of the kinematic equations while studying math in school. Love this series and looking forward to more.
Ah, finally! I tried to use this to create a bomb-like weapon that fires in an arc last month, but I couldn't get it working, even though I had Physics in high school and wasn't too bad at it. Damn, I forgot a lot of the essential equations. It's all coming back to me now. I even managed to solve the question at the beginning of the video before continuing.
Also, the debug path thing is bound to be useful.
Thanks for the video, Sebastian!
im planning to do physics next year, is it worth it?
@@mangomanlassi7779 I’m late, but I’d say physics is pretty useful in helping you understand a lot about things like kinematic equation as seen here but also to other things that will help you with realistic object collisions, etc
I'm addicted to game development videos now without people like you i'd be dead Thanks alot for doing these videos
You know when it comes to hard stuffs, we always end up on your channel! We really love what you do Sebastian! Thanks for having us indie's back!
May I ask what kind of game you're making?
@@CraftBasti I made some peojectiles using this
@@Zihan118 obviously, but what genre of game are we talking about? 3D RTS? 3D FPS? 2D Side Scroller?
CraftBasti bump.
Fantastic! I looked at several approaches that didn't work quite right before I found yours, and this calculation is PERFECT!
Thank you so much for this, the AI couldn't just help me with creating an equation that would work, but this not only teach me a lot of stuff but helped me solve my problem, thanks a lot!
I adjusted your code to calculate where the ball will land if the target were moving at a constant speed. Thanks to you, I actually completed my project!
How did you do that? I'm having trouble with that issue
Holy shit, I've been searching for this kind of thing for so much time now and it turns Sebastian had such an awesome tutorial for this, this whole time!
Solved the problem I was struggling with for like 5 days.. Thank you so much.
Sebastian you saved someone's life today thanks man for the tutorial and alll the math you explained
This problem took me a couple years to solve for the Minecraft Mod: OpenBlocks's Canon. Thanks for a nice explaination - years later ;D
You'r a genius, man! Fantastic, finally I found exactly what is needed!! Thank you!
Thanks for doing this tutorial. It would be cool to see how it works with a moving object. I think I can figure it out given this foundation, but you are the king and your tutorial would probably show me things I'm missing. Good job!
*Meant moving target, not object.
Just a heads up... if you set the Gravity to -60 ish, then the ball misses the target. Any idea why?
rigidbody.velocity assign attempt for 'Ball' is not valid. Input velocity is { NaN, NaN, NaN }.
UnityEngine.Rigidbody:set_velocity(Vector3)
Will you continue this series? I would like to see more and learn more in your way of teaching. It's really helpful
it is 1am and I finally understood, thank you for the video you make it easy to understand
omg i was going to suggest this as a video i thought would really suit your channel and I happened to be having some problems with it, just happened to glance through your videos and BOOM, thanks!
Thanks, I feel like Isaac Newton now. Super satisfying to see the ball always hit the hoop perfectly :D
Hi, You and Your solution are awesome ;) There is one small improvement that can be made, at least to Your code on github. I would call Mathf.Abs() on every math inside MAthf.Sqrt() and than it can also work if target is lower than ball :) Thanks again for this great video.
hey man , could you please do your change to code. obviously there is an issue with current one.whenever i move the target object and the curve is about to become a straight line the curve will be disappear and everything mess up ):
You are amazing! Your videos solve so many my problems during game developer work... i so love you! THANK YOU SO MUCH! I really try boost up my mathematics skills but some tasks is really difficult.... you are great...
Amazing explanation sir :)
Thank you for making whole process simple.
Thanks very much! Changed the code and using it for a 2D game. WIll use for a 3D game in the future. Many merits.
But not work for negative gravity :s
Vector3 DisplacementZ = new Vector3(0f, 0f, Target.transform.position.z - Ball.transform.position.z);
Vector3 velocityZ = DisplacementZ/ (Mathf.Sqrt(-2 * height / Gravity) + Mathf.Sqrt(2 * (DisplacementY - height) / Gravity));
add these 2 lines of code and works in 3d, i mean when u move the object left and right
don't forget to change displacementXZ to displacementX and then set its Z coordinate to 0. then your code works great :D
How would you go about using these equations to calculate the impact point of a thrown object? Every example I've seen predetermines the final position, but I want to know the landing point, given the initial velocity.
Steven then x=initv*time-0.5gt^2
Math is magic!! thanks for this. I'm using it for a baseball game with players throwing the ball back and forth
Thanks for this fantastic lesson, very useful for my game.
i love this Equations series
i know we cannot control the speed of ball but is there any work around ? i am making football shoot game
Wow, this was really awesome. Thanks Sebastian!
Lovely tutorial. Except you didn't had to drive a formula for initial velocity for horizontal. You can directly use V = d/t and that's what your derivation ends up at.
Saved me from a job challenge
The 12 dislikes are from people who had a positive gravity
due thank you so much for making this. i was tryna implement somethig like this into my recroom game and i was having a brain aneurysm tring to put the equations in. Instant Like and sub
Great video, I played around with it a bit. If I assume the ball is a soccer ball and add a reasonable drag coefficient(Cd) on the ball, say 0.25 - then the ball stops about half way. Is it possible to modify these equations to take into account the Cd ?
Does anybody know how I might be able to do this ?
(edit) The equations Sebastian provides is for 'high school' physics. When you add a drag coefficient onto your ball then the formulas don't work anymore. This is bc of air resistance (drag). There is an eq for air resistance but it is not a one time formula, you need to keep applying it per frame. Hence you cannot predict exactly where the ball will land. You can use integrals to get a fairly accurate path but in Unity it is not 100% accurate.
Super Awesome tutorial thanks Sebastian . But Why this not works if target position is too high ?? How to solve this ??
Great work, very helpful. Thank you
took me back to college days
Thanks a lot man !
That helped me a lot in my Unreal project !
i think i saw one video where you show some of the games you made through the years, and there was a game i would like to know how to make it, its like a mouse cursor dodger, where you need to try click a moving target on the screen, the target will move around and away from your mouse cursor on a precise way, dodging your cursors velocity maybe...? it didnt look like randomly moving cause that would obviously make the dodger fail by walking into your cursor x y position...
i didnt find it again, can you tell me about it?
i searched for something along the title, click, "hi everyone" IT'S HIM
All I can say is , its time to subscribe ..superb
Thank you, but is there any reason that checking debug is not showing draw path? Everything else works perfect good work !!!
GRRRRRREEAAATT HELP! Thanks a lot Sebastian
Is it possible to change the speed of the moving projectile without causing it to leave it's arc?
Thank you Sebastian
this was amazing please continue ....
TYSM! This was a very useful tutorial.
Physics.gravity affects all objects in the scene. Is there a esy to do this affecting the gravity of this single object?
If the ball is missing the center of the hoop by 0.5 to 1 unit, this *might* help: I haven't watched the full video, but I asked about this for the first video (Mario jumping) on the Unity forum, and while I didn't understand the full explanation, apparently it has to do with Unity using semi-Euler approach to physics and not calculating the velocity based on the first physics frame but the second instead (or something like that). Try adding "... + (0.5 * Time.fixedDeltaTime * (whatever your acceleration is, the gravity) * -1) * Vector(dot)one" to the initial Rigidbody2D velocity and see if that helps.
Where did you get this formula from? I can't get the ball to hit the center with either Sebastian's original code or your addition
This is the most thorough explanation of the subject I've seen so far. One question regarding the for loop when drawing the line: Is it a valid way for an AI to check if he can jump on a point (and not hitting the ceiling e.g.) or is there another way of doing it?
It is a good way, although obviously you can use a much lower resolution.
Hi Sebastian , I'm making a space exploration game in unity and the planet terrain has been stumping me for a while now and I was wondering if you could possibly help me at all or make a procedural planet series?
Dude, you are fu*king awesome. Thanks a lot.
How can I make flying object (let's say a missile) to look in the same direction as tangent to parabola ?
I'm looking for the same answer too
Why did you choose equation 4 for solving t? Wouldn't any of 1-3 work also?
I have a question, why did you use 18m/p^2 instead of 9.81m/s^2?
I prefer the solution + given information to all be integers for example problems.
I got you, my ocd was like hold up! XD Nice Video Btw!
+Ran Crump *ocpd
Probably because he wants to put that value. As a programmer you can make your own Physics engine and that includes switching the real values for values you want. If you write the code in the video and change the gravity default value for -9.81 you will have a good result using real values.
For those want to change the velocity to get to the target, you can simply increase the gravity apply to the launch object.
I am using this method in my 2D project and I don't want to change the whole Physics2D setting. So I make Rigidbody2D.gravityScale = gravity(in this video) / Physics2D.gravity.y;
How would I change the speed of the ball?
Looking to create a script where a game object moves in a parabola from point A to point B , unlike this video where physics works, I just need it the game object to travel between those points, any help on that ?
Old but very nice tutorial, however, I can't figure out why you have taken the gravity as -18 m/s2 instead of -9,81 m/s2 as it is supposed to be. This deviated the simulation 1.4 times off of the reality.
It should also take into account the mass of the object. And do not start from the value of 1.
What difference do you expect the mass of the object to make?
I'm sorry. All formulas are mass independent - Trow ball by velocity, not by AddForce or else. My mistake. I checked your example on my project.
Great, awesome. Thank you very much
Love you Seb!
Great tutorial.
is there a tutorial for this in gamemaker studio 2
Now I can create a shooting mechanic for my basketball game!
Did it work?
AWESOME, MAN!!! THANKS A LOT!!! Thats what i need!
really helpful. Thank you Sir
This is amazing! Thank you so much!
i think (velocityXZ + velocityY * -Mathf.Sign(gravity)) is equal with velocityXZ + velocityY. why need to times -Mathf.Sign(gravity) ?
Ive got a question, is it possible to calculate this if you know the horizontal motion and not the highest point?
Thank you!
if we consider some drag force in forward dierction than what will be the changes
how can i make that trajectory visible after build?
Does anyone know how I would be able to implement a projectile-motion-like approach to this ? I have a very similar situation, but with a cannon, so the cannon's rotation needs to influence both the x and y velocities. I have already tried implementing the cos(angle) for the x speed and sin(angle) for the y speed, but it didn't work 100%...
Maybe someone solved this problem already but I cannot stick my head around it. I copied the code exactly as written in this tutorial but the center of my ball seems to miss the center of the target by about 0.5 on the x-axis. The calculated velocity is the same and I positioned all my gameobjects as in this scene... Anyone having an idea about this weird behaviour? I tried to watch this video in slow motion but I just cannot see wether the ball trajectory would hit the targets center given the colliders would be inactive.
is there a way to manipulate the speed with this?
so question. I wanted to get this equation to work in a unity project, but I am wanting to use it with a grenade, so I place an empty object in front of the player, and that is the endpoint and the player is the start point. I can not figure out how to convert it tho, any ideas?
Great video Sebastian, but what if you don't have the max height constraint and you still want to shoot an arrow in a curve between two points.
I think you'd need to pick a height, since an arrow can be shot in a curve between two points in a number of different angles, even in a straight line. If it were three points then you could use the middle one as the height
Could you do a tutorial on leading a target? Like for a sports game...
Can’t find link of the first episode.
how to calculate the wind (x-only), for this formula: VelocityX = DisplacementX / (Mathf.Sqrt (-2 * h / gravity.y) + Mathf.Sqrt (2 * (DisplacementY-h) /gravity.y)); ?
Who knows?
How to calculate g if h and t is given?
Hey Sebastian, awesome tutorial, I've been tinkering with this problem for a while now, you really helped me out, but I've one question, could you explain how I could apply this to a moving target?
Emiel van Essen i have a video on my channel on a turret that hits moving target 100% of the time
Also works in 3D
Thank youu. You are great ^^
Great tutorial thank you
-18 m/s2 downwards is up
my god... copy paste... i love you
Great, great stuff
Hey,
I'm not sure if this is in the video but...
Is it possible to adjust the speed of the ball?
kind regards
I'm not sure whether you understood the purpose of this video. The ball's speed is actually being calculated in script so it always hits the target. Setting/adjusting the speed of the ball is easy.
i have the same question is there any work around ?
how can i increase the speed?
Hi, I found a solution to some extent. You can decrease the gravity value to -40 for a quick ball and increase it to -5 for a really slow ball. This is not the best solution, but it works as long as you don't change the values too much.
first i did it with timescale when launching ball .second s0lution is to increase the velocity on z axis but it will cause accuracy problem
ty sooooooooooooooooooooooo much
really thank
I know this is an old video but how would you dynamically change the height of the arc based on the distance you are throwing it rather than have it as a set value?
I think you have to fix velocity or other parts to do that... In this case he fixed height.
Question, are you done with the procedural terrain series?
+Sujisan4 I am not. I had planned to release the next episode end of nov, but looks like it will be early dec instead.
Thank you!!
Wow, amazing, thạnk you !
Helpful video. But i have a question:
How can i decrease the time?
The rate of fall is a constant irregardless of the forward velocity of the ball. So to get the ball to hit a fixed target simply make the arc shallower. e.g if target is at 9, make the highest point of the arc, H, 9.0001
mate could i change the speed the ball is travelling at ?
If you increase the gravity, the speed will be faster to compensate. If you decrease H (peak height) then the ball will be more direct and will have to go faster to counter gravity. But outside these constraints, going faster just means you miss the target in a purely physical simulation.
One option is that instead of a Rigid body you could use this math to create an animation and you can play that animation at any speed you like.
my life saver :)
Got so lost at the lets draw a line part 😂😢