1 / 22

Movement and physics

Movement and physics. Mark Nelson mjas@itu.dk. Movement. You will probably want some things moving Lots of ways to do that General tradeoff between physics and animation And hybrid approaches. Basic movement model. Recall Pong Velocity per object Update position per frame

anneke
Download Presentation

Movement and physics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Movement and physics • Mark Nelson • mjas@itu.dk Fall 2012 www.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? Physics can be an awkward inverse problem Want a specific smooth motion: Have to calculate what combination of forces would produce it Then run a physics simulation just to get that back again

  9. 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

  10. 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

  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)2P0 + 2(1-t)P1+t2P2

  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

More Related