Let’s Build a Physics Simulation (PONG: Part 2)

  Рет қаралды 2,511

MinuteLabs.io

MinuteLabs.io

Күн бұрын

We finish building our version of PONG!
Find Part 1 here: • Let’s Build a Physics ...
Finished Product:
playcode.io/642557/
----
If you get something out of the work I do, consider sponsoring me on either:
Github Sponsors: github.com/sponsors/wellcaffe...
Patreon: / minutelabsio
----
Contents
00:00 Introduction
00:56 Using vectors for collisions
23:13 Making paddles
32:48 Moving the paddles with the keyboard
44:31 Paddle collisions
53:20 Scoreboard
1:05:51 Conclusion

Пікірлер: 27
@Minutelabsio
@Minutelabsio 3 жыл бұрын
Don't forget to share your playcode links! I'd love to see what you build! As with last time, I'll try my best to answer questions in the comments.
@ultrio325
@ultrio325 3 жыл бұрын
will do Update: All well and good until the part about vectors Update 2: Lost all my code
@usama57926
@usama57926 3 жыл бұрын
Love your explanation & love method you use to build this game.
@PowerhouseCell
@PowerhouseCell 3 жыл бұрын
This is so fun to even just watch! :D
@yklcs
@yklcs 3 жыл бұрын
Nice! I'd do the specifics of the animation a bit differently if I were to implement it. 1. Use `requestAnimationFrame` instead of `setTimeout`, and adjust `dt` accordingly 2.1. Use separate `canvas` for the paddles and balls 2.2. Setting `fillStyle` is expensive to call each frame, so just set it globally. Also, constraining the initial randomized velocity vector so that it doesn't take forever to reach the paddles would be nice too.
@Minutelabsio
@Minutelabsio 3 жыл бұрын
What do you mean "if"? Show us the code, friend!
@rubensimons3553
@rubensimons3553 3 жыл бұрын
I would love to see some other tutorials.
@Minutelabsio
@Minutelabsio 3 жыл бұрын
I'm planning on doing more!
@UnPuntoCircular
@UnPuntoCircular 3 жыл бұрын
HAHAHAHAHAAHAH aqua is fine, but I prefer royal blue 10:39
@discreet_boson
@discreet_boson 3 жыл бұрын
This is awesome
@usama57926
@usama57926 3 жыл бұрын
Yes I love to see your tutorial on asteroids game.
@saulcorralsanchez4460
@saulcorralsanchez4460 3 жыл бұрын
So nice to start learning both JS and how to code phyisics simulations! After a few hours, and lots of topographical errors, I've made your pong version work. Now it's time to play with it! (with the code I mean) By the way, how do you put double slashes in multiple lines at the same time? Just as you do in min. 19:54 Thanks for the series of videos, trully usefull and enjoyable!
@Minutelabsio
@Minutelabsio 3 жыл бұрын
Thanks for the kind words! In order to bulk comment you can use ctrl-/ or command-/ on mac. Post your code when you're done!
@JaX0rton
@JaX0rton 3 жыл бұрын
Who's doing the text commentary on the video? You're hilarious!
@JaX0rton
@JaX0rton 3 жыл бұрын
Thanks for sharing your version. It helped me add my mods quicker. I'm a full-time programmer but I have almost no JS experience so having a template really helped me focus on my ideas and bring them to life and not be super bogged down by language syntax. Here is my modded version: playcode.io/657056 List of features: 1. Spin: Implement newbie spin implementation that changes the direction of the ball based on the relative movement of the paddle and ball. If the paddle is still, simple reflection occurs 2. Exciting starting angles only: Start ball angles are always between 10-70 degrees. Too vertical and too horizontal and the game gets boring. Adding spin onto the ball helps make it exciting again 2. Resets: When a round finishes, the players always start from the center Stylistic code changes: 1. Use JS string interpolation when fetching the document "playerXscore" 2. Other minor readability changes Future features to implement: 1. Implement paddles as a box (4 bounded lines) instead of a single line to avoid weird animation where the ball overlaps the back of the paddle when coming in from an acute angle 2. Progressive increase in paddle and ball speed as a rally (number of successive shots) goes up 3. Implement acceleration for paddle movements (velocity won't go from 0 to max directly but it will go up linearly until an upper bound) Future feature #2 could also be implemented as an acceleration function. Does anyone else have any other ideas for features to implement? +MinuteLabs.io: I have 2 questions for you. 1. Does the game ever stutter for you? This might be because I'm running my laptop off battery and power saver is reducing my CPU clock. I'll test this on AC power next time and see if it's any better. I don't think the GPU needs to kick in for this one (I'm on a newer MBP which has a switchable graphics card) 2. I couldn't find a standard spin implementation so I devised a simplistic one based on my intuition from my days of playing ping pong IRL. Quick searches didn't give me good reference material on how to model the physics behind it (most talked about complex airflow dynamics which I sort of understand from playing the game but don't want to model). Got any tips for me?
@Minutelabsio
@Minutelabsio 3 жыл бұрын
Looks nice! The stuttering might be because we're doing a naive animation loop (I'll augment this in the next video to optimize it by using requestAnimationFrame) The spin would probably involve adding an angular velocity to the ball which could be stored as a property on the ball. Then when contacting a surface, you'd need a more involved bounce algorithm to handle this. The algorithm gets a bit involved. Look for "moment of inertia" "angular velocity".
@PolineChan
@PolineChan 3 жыл бұрын
i followed the first part, but got a little lost for the second part. i tried to modify to much and when things goes wrong, i don't know what to do lol.
@PolineChan
@PolineChan 3 жыл бұрын
@MinuteLabs.io could you do tutorial on adding gravity to the object. i think it should be recursive call and change the vy. i want your insight on how having it on an object and make it global.
@Minutelabsio
@Minutelabsio 3 жыл бұрын
That's the next video :)
@usama57926
@usama57926 3 жыл бұрын
10:53 Are you using *dot product* to find projection .....❓❓❓❓
@Minutelabsio
@Minutelabsio 3 жыл бұрын
Yes, inside the vector library, the projection function uses a dot product
@ultrio325
@ultrio325 3 жыл бұрын
I'm going to add more to this game of pong I might make
@Minutelabsio
@Minutelabsio 3 жыл бұрын
cool. share your playcode link!
@ultrio325
@ultrio325 3 жыл бұрын
@@Minutelabsio nope, not yet
@hasifaiman
@hasifaiman 3 жыл бұрын
This video is useful for me to get to sleep... Thanks!
Let’s Build a Physics Simulation (PONG: Part 1)
41:27
MinuteLabs.io
Рет қаралды 10 М.
Simulating Lifespan (Why do blobs die around age 2?)
9:33
MinuteLabs.io
Рет қаралды 159 М.
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 42 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 33 МЛН
PINK STEERING STEERING CAR
00:31
Levsob
Рет қаралды 21 МЛН
Кәріс өшін алды...| Synyptas 3 | 10 серия
24:51
kak budto
Рет қаралды 1,3 МЛН
This lab took me 6 years to release
3:25
MinuteLabs.io
Рет қаралды 11 М.
Interactive Evolution Simulator
11:22
MinuteLabs.io
Рет қаралды 208 М.
Proximity Graphs with Gravity | Let's Build a Physics Simulation
55:51
4090 from eBay for $200-$300 bucks
3:47
northwestrepair
Рет қаралды 34 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 380 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 601 М.
Dragon vs. Airplane - Which Is Faster?
2:31
MinuteLabs.io
Рет қаралды 11 М.
This INCREDIBLE trick will speed up your data processes.
12:54
Rob Mulla
Рет қаралды 257 М.
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 25 МЛН
Apple watch hidden camera
0:34
_vector_
Рет қаралды 64 МЛН
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 44 МЛН
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 6 МЛН