How to make your GAME feel AWESOME
Making you games FEEL AWESOME
Improving your movement code
In this tutorial, I will explain to you how to take the player movement in your game to the next level: by adding acceleration, friction and all sorts of goodness.
I will teach you the equations needed to implement that on your own game (no matter the game engine) as well as how you some code example.
This is clip from the "How to Program a Game in C++" tutorial series. If you want to learn more about game development, be sure to check them out here: https://www.youtube.com/playlist?list...
I hope you enjoy it!
Download this tutorial's source code: https://danzaidan.itch.io/pong-learn-programmingTutorial Transcription:
Now let's learn about the equations of motion so we can make out player movement feel great!
Previously, we added a position variable that we incremented every frame, by an velocity amount.
The velocity is the rate of change of position in time, so we can call that the derivative of the position.
What we want to do, is to make the velocity have its own variation in time. So that it picks up speed over time.
So the derivative of the velocity will the acceleration, which is the rate of change of velocity in time!
So when the player presses the move button, instead of changing the velocity, we'll change the acceleration.
Since the acceleration is the change in velocity over time, we can easy calculate the new velocity by adding the old velocity to the acceleration times the delta time. Pretty much like we were doing before!
And now for the position. Since we are considering both the first and second derivatives (the velocity and the acceleration) our equation has consider them both.
So the new position will be the old position; plus the velocity times the delta time (like we did before, since it's the first derivative); plus the acceleration times the delta time squared, divided by two.
If you want to know where this equation comes from, you can watch calculus lessons online. Khan Academy has great videos on that!
Now let's program that!
I'll have to store the velocity across frames, just like the position. I'll call that dp, since it's the derivative of the position, like we discussed.
The acceleration, called ddp (since it's the derivative of the derivative of the position), I'll create every frame, because I'll only accelerate the player the frame the key is being held.
So if it's down, I'll add acceleration.
Now all I have to do is to add those equations we discussed: the equation for the p, considering both derivatives, and for the velocity.
Look at that! We already have nice and smooth acceleration.
But it feels like we are floating in space... Because we have to friction!
The friction will be a change in the acceleration, and it will be based on the velocity. That simple. Those values we can tweak to get the game exactly how we want it: maybe more Super Meat Boy-like, or maybe more like Mario. You got the idea.
Now we have an awesome movement! And that feels really nice to control!
Get Pong - Learn Programming
Pong - Learn Programming
A simple pong game with accompanying tutorials and source code
Status | In development |
Author | Dan Zaidan |
Genre | Action |
Tags | 2D, Arcade, Casual, Fast-Paced, Open Source, Pixel Art, pong, Tutorial |
More posts
- [COMPLETE TUTORIAL] How to make a game in C++!Sep 26, 2019
- How to make an AI for GAMESSep 23, 2019
- Tutorial #5: Enemy AI, Score System, Finishing the GameplaySep 18, 2019
- Introduction to Collision Detection For GamesSep 08, 2019
- C++ Tutorial: Gameplay, Movement and CollisionSep 04, 2019
- Tutorial: Player Movement, Input and TimeAug 23, 2019
- Tutorial: How to make a software renderer to display graphicsAug 16, 2019
- Learn how to make a game in C++Aug 07, 2019
Leave a comment
Log in with itch.io to leave a comment.