Chapter 23 — Movement, Velocity, and Simple Physics
Part 2A — 2D Game Fundamentals · Chapter 23 of 62 · 8 hrs
Chapter 23 — Movement, Velocity, and Simple Physics
Level: intermediate Estimated time: 8 hrs Prerequisites: chapter 20 (game loop, delta time), chapter 21 (Canvas), chapter 22 (sprites and animations), and the OOP from chapters 08 to 11 What you'll be able to do by the end: write your own 2D vector class, apply gravity, and make a character jump with variable jump height, a double jump, coyote time, friction, and a bounce — all in pure Flutter, with no physics engine.
23.0 — Chapter objectives
By the end of this chapter, you will be able to:
- clearly distinguish position, velocity, and acceleration, and say what unit each is expressed in;
- explain what a 2D vector is and why a game needs one;
- write a complete, immutable, testable
Vec2class from scratch; - overload the
+,-,*, and==operators in Dart; - compute the length of a vector and normalize it;
- diagnose and fix the famous faster diagonal movement bug;
- use the dot product to tell whether an enemy is in front of or behind the hero;
- measure a distance between two points without an unnecessary square root;
- convert a vector to an angle with
atan2, and an angle to a vector; - write the
position += vitesse * dtandvitesse += acceleration * dtintegration steps; - explain why the order of these two lines changes the result;
- compare explicit Euler and semi-implicit Euler, and choose the latter knowingly;
- apply gravity, stop a fall on a ground, and trigger a jump;
- implement the double jump, the variable jump, coyote time, and jump buffering;
- add friction, damping, and a maximum speed with
clamp; - tune a character's acceleration and deceleration to get good game feel;
- make an object bounce with a restitution coefficient;
- write a circular motion and a linear interpolation (
lerp); - make a camera or a pet follow a target smoothly;
- program a screen shake and a knockback;
- assemble a complete Dart Dungeon character that runs, jumps, falls, and slides.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion