Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Nelson Movement and physics Fall 2013

Similar presentations


Presentation on theme: "Mark Nelson Movement and physics Fall 2013"— Presentation transcript:

1 Mark Nelson mjas@itu.dk Movement and physics Fall 2013 www.itu.dkwww.itu.dk

2 Movement  You will probably want some things moving  Lots of ways to do that  General tradeoff between physics and animation  And hybrid approaches

3 Basic movement model  Recall Pong  Velocity per object  Update position per frame  Control by changing an object’s velocity:  Rotate  Speed up / slow down

4 Smoothed movement  Instantaneous velocity changes aren’t always great  ”Natural” motion is often non-linear  Mario moving platforms speed up and slow down at path ends  Even blinking lights aren’t always linear

5 MacBook sleep indicator LED curve

6 Simple smoothing  Send velocity changes via an API  Now, each game-loop iteration:  Update position based on velocity  Update velocity based on curve  Can be pre-programmed animation (platform movement)  Or, reactive (e.g. with some lag)

7 Physics-based smoothing  The reactive version is basically velocity+acceleration:  Objects have velocity  Positions are updated based on velocity (1st derivative of position)  Velocities are updated based on acceleration (2nd derivative of position)  Acceleration can be the basic unit, or computed from force  F = ma, so equivalent for a constant-mass object

8 Physics versus animation  Why not always physics?

9 Inverse kinematics  Kinematics:  How objects move in reaction to forces  Inverse kinematics:  How to apply forces to get objects to move in specific ways  Hard in general

10 Curve-following  Say we want to follow a specific curved path  Robotics-style reactive controller:  If we’re off the path, apply corrective velocity  Produces smooth, physically realistic, but ”laggy” path following  Can follow more closely:  Predictive controller, e.g. start turning a bit before a turn  Analytical solution, like calculating a satellite’s thrust schedule

11 Some more pros/cons  When not physics:  Weird emergent effects to debug  Want effects you don’t want to fully simulate, e.g. tractor-beam motion  When physics:  Want unscripted interaction between animations and other objects  E.g. Platform on a pre-animated path, but can be knocked off-course by player colliding with it

12 Some animation approaches  How do we follow a path?  Waypointing  Animator gives specific points on a path  Animation system moves objects between them  Simplest is just drawing straight lines, but often want smoothing

13 Parametric curves  General representation of paths  Function X(t) gives object position from t_start to t_end

14 Bezier curves  Probably the most common parameterized curve  Quadratic Bezier:  X(t) = (1-t) 2 P 0 + 2(1-t)P 1 +t 2 P 2

15 Some facts about parametric curves  speed(t) = |X’(t)|  distance(t) = integrate speed(t) from t_start to t Plus, lots more useful relationships, e.g. curvature

16 Constant-speed motion  Often want to move at constant speed along a curve  Or at least, want to control our speed separately, by varying t  Not always easy to define a curve so that it comes with constant speed(t)  Solve by noticing:  Constant speed means constant distance traveled

17 Constant-speed motion  Reparameterize by arc length  Choose desired arc position p we want to be at  Solve distance(t) = p  Done by finding root of distance(t) – p = 0  (Requires numeric integration, usually Newton’s method)

18 Bezier paths

19 Bezier curves  Notice that almost all Bezier curves don’t start out as constant-speed curves!  Also, can sometimes have weird artifacts  Loops, backwards travel  More common in higher-degree curves  May be inappropriate, or need more constraints, if you have obstacles

20 Physics engine  [see other slides]

21 2d platformer physics  Similar general principles  But some things can be simplified  Grid-based methods  Pixel-based methods  Collision response  Bouncing off, stopping  Special-case being ”on” a surface

22 2d platformer physics


Download ppt "Mark Nelson Movement and physics Fall 2013"

Similar presentations


Ads by Google