Physics For Game Developers 328
Physics For Game Developers | |
author | David M. Bourg |
pages | 326 |
publisher | O'Reilly |
rating | 8 |
reviewer | Richard Jones |
ISBN | 0-596-00006-5 |
summary | A good introduction to the difficult subject of writing 3D games and simulations with accurate physics, let down by a few minor snags. |
Programmers who want to get serious about game physics will love David M. Bourg's Physics for Game Developers. As I've said, the subject is inherently very difficult, and the book assumes that you are already familiar with vector and matrix arithmetic up to college level, integration and differentiation, and at least you hazily recall your mechanics/physics lessons from school. You also won't be afraid to wade through Bourg's carefully documented derivations of formulae for various physical effects, and his well-commented source code.
The book starts off by recapping the basic concepts of mass, centre of gravity, moment of inertia and inertia tensors. Bourg assumes that you have a working grasp of these subjects, and I admit that I had to go back to some of my A-level mechanics text books. He then goes straight into kinematics, where he uses standard (but forgotten!) integration techniques to calculate velocities from accelerations and positions from velocities. His examples are excellent, although a few exercises wouldn't have gone amiss. The chapter on forces covers a great many different types of forces such as springs and buoyancy, but curiously omits the important subject of contact forces (the normal force that a table, for instance, exerts on your computer monitor to stop it falling through the floor). In fact contact forces don't appear until much later in the book. Particles, rigid bodies and impulses (forces from collisions) are introduced in chapters 4 and 5.
At this point I have to say I was a little bit confused. What did this have to do with game programming? Everyone knows that games spend most of their time running round a single big "main loop," working out the forces on each object, looking for collisions and working out which keys the user is pressing. It doesn't seem imaginable that a game programmer could completely solve all the equations of motion by pure integration at the beginning of the game, and then just run the positions of the players through the graphics engine like a movie!
I already knew a little about this from what I'd found from the web, but what most games actually do is calculate all the forces on all the objects (players, scenery, etc.) in the game, and then integrate them at each step. Some of these forces will be generated by human players pressing keys on the keyboard or wiggling the joystick, and that's how the objects end up moving. Pure integration isn't usually possible, so the physics engine performs numerical integration - a kind of fast approximation to the pure "closed form" solution. Numerical integration is itself a tricky subject, but it's the meat-and-veg of good game programming. Surprisingly, numerical integration and a realistic main loop doesn't appear until chapter 11 (172 pages into the book). I skipped straight to this section, and I suggest you do so too...
The chapter on numerical integration is excellent and contains the first realistic gaming (or at least simulation) code. Many games I've examined use simple numerical integration, like this:
// At each step ... A = acceleration, dt = time step
Vx += Ax * dt;
Vy += Ay * dt;
Sx += Vx * dt;
Sy += Vy * dt;
Unfortunately this method (Euler's method) is very inaccurate and unstable: if you tried to simulate planets orbiting around a sun using this method, they'd soon fly off into outer space unrealistically. Bourg gives an excellent introduction to better methods such as the "improved Euler" method and the popular Runge-Kutta method, and he covers them in a context which will make it clear how to use these methods in your own programs.
The book reaches a crescendo with three fully developed simulations: two hovercraft which you can drive around and jolt into each other like bumper cars -- they spin around realistically; a flight simulator; and a 3D car which can be crashed into blocks that bounce around. Again the source code is meticulously commented and generally well written. My only two reservations about the code are: It would be nice if Bourg had chosen to use OpenGL instead of Direct3D so that those of us without regular access to Windows could actually compile and run the examples. The book would make an ideal companion to the OpenGL Red Book. And coming firmly from the Windows camp, Bourg's examples are full of all the horrors of Win32 APIs and Hungarian Notation. But maybe that's just my personal preference :-)
So in summary: The Bad Points:
- Measurement systems: Bourg moves uneasily between the English/US system and the European SI units. So we get examples which combine ft/s, meters, slugs and kilograms, uneasily converting between the two. He should have chosen one system and stuck with it.
- A common complaint about computer books: I've just spent 25 quid on a book which will sit open on my desk for months. Is it too much to ask that it be ring bound?
- Some subjects are not explained in enough depth. Particularly: moments, contact forces, impulse methods. Bourg should probably have written a chapter or three on collision detection.
- The chapters are presented in a very strange order. Move chapters 6-10 until later, or introduce numerical integration earlier.
- A few of the illustrations are inaccurate.
and The Good Points:
- Considerably better than the usual round of maths/physics text books which make up this field. In fact, this is really one of only about 2 or 3 significant books in this area which are pitched for game developers as opposed to mathematicians, and it's certainly the best.
- The areas which are covered are done well, in significant depth, with a good bibliography where you can find out more.
- The commentary on the difficult equations is good, and Bourg resists the temptation to derive many of the formulae he presents, instead referring interested readers to other references.
- Code is well documented and explained.
And now I suppose I have no excuse not to resurrect XRacer :-)
You can purchase Physics for Game Developers at Fatbrain
Baldur's Gate for PS2 (Score:3, Interesting)
-sam
Physics in games (Score:2, Insightful)
Re:Physics in games (4D Stunts Driving) (Score:2)
How about "extreme game programming"? (Score:3, Insightful)
So pair up a couple of guys. One to worry about the artistic design, and another to worry about realistic physics.
Re:How about "extreme game programming"? (Score:2)
I'm with you on switching modes between creative stuff and technical though. Although I guess it depends on what you're doing. If all you're doing is coding, then since that's all logic, physics should fit right in there with it.
My biggest problem is switching between programming and graphic design. Oh the headaches.
Re:How about "extreme game programming"? (Score:2)
Indeed it does. I am a senior programmer currently working at a web agency, but have no formal programming qualifications. My degree is in Physics and, while I did take some programming modules during the course of it, all of these stressed the numerical/physical aspects above the coding ones. In fact, the only language I have ever been taught is Fortran; I taught myself C, C++ and Java. (and BASIC, a smattering of assembler, perl, etc, of course)
I can imagine that it would be just as easy for a CS graduate to pick up at least basic Physics on their own. There isn't really anything that tricky in the sort of mechanics that would be required for most games (fluid dynamics not withstanding, but I have yet to see really realistic water in a game anyway
Cheers,
Tim
Re:How about "extreme game programming"? (Score:2, Insightful)
Actually, Half-Life is based upon the Q2 engine and is a lot better than Quake 2 itself.
Maybe John Carmack should just focus on building 3D engines which game developers could than use to produce brilliant games.
HL (Score:2, Informative)
Troll? (Score:3, Informative)
Hrm. Seems my last five comments have each been modded down one point. Fortunetly for me, I could care less.
Re:How about "extreme game programming"? (Score:2)
Isn't this what he does? He also has a quick&dirty design team to make a bare-bones engine demo (The Quake series) which is also fun.
Physics isn't everything (Score:3, Insightful)
Re:Physics isn't everything (Score:4, Interesting)
Re:Physics isn't everything (Score:2)
Whether the physics model is realistic or not, every game has to have one. Even if you choose to calculate position, motion, and reaction and stuff in a way very different from the one that applies to the real world, you have to calculate those things somehow.
That's the point of this book.
A better book to read for Game Physics... (Score:3, Insightful)
Lets face it, the best physics is REAL physics.
If you want your game to have good physics, then slap a good physics engine (based on real formulae) into it!
Re:A better book to read for Game Physics... (Score:2)
ISBN: 0030317169
Price: $143.00
Re:A better book to read for Game Physics... (Score:2, Insightful)
Sure, the formulas used are *based* on the regular "scientist" formulas, but they *have* to be approximations. The book tells you how to use do those approximations.
If you give a coder a standard physics textbook and tell him to code a physics engine, he'll either implode or spend ages working out numerical methods for approximating real physics... exactly what is in this book.
"real" physics?! (Score:3, Insightful)
Second, the usual 100-level undergrad textbook in physics tells you a lot of things that you probably don't need to know when designing games (like E&M and some quantum mechanics), but also leaves out the more practical aspects of classical mechanics when dealing with less-than-ideal objects. Once you work with the motion of objects that are not spherically symmetric, you need mechanics at the next level, and you need to work with matrices and vectors. This stuff isn't difficult, but it's not in the typical undergrad textbook. And it does require a bit of mathematics, like most things that are worthwhile.
So it sounds to me like this book does have an important niche to fill, combining undergrad classical mechanics, a sampling of junior-level classical mechanics, and some numerical methods to boot.
Re:A better book to read for Game Physics... (Score:2)
Physics texts cover the physics behind the action, but a book like Numerical Recipies goes over the implementation and would be a very good complementary book.
The other thing to keep in mind is that the more accurate the physics gets, the more computationally intensive the game becomes, so a game may not be able to achieve those 150 fps everybody seems to want when doing accurate physics simulations.
Re:A better book to read for Game Physics... (Score:2)
Re:A better book to read for Game Physics... (Score:2)
Numerical Recipes in C : The Art of Scientific Computing
Comes in a variety of flavours including C++ and Fortran.
Re:A better book to read for Game Physics... (Score:2, Funny)
Don't need to be that exact (Score:2, Insightful)
I think it is more important to include as many effects as you can: gravity, linear momentum, angular momentum, elastic/inelastic collisions, friction (surface and wind), than it is to model the effects perfectly.
In fact one could argue that it is to the game designer's benefit to use an innaccurate and exaggerated physics model. Most real world collisons with the guard rail on a race course are relatively unspectacular (by design) - but that would be oh so boring in a racing game now wouldn't it?
-josh
Re:Don't need to be that exact (Score:2)
If your game lacks a good physics model, players are going to find that it "feels funny." They don't mean that it isn't realistic, rather they mean that your game isn't consistent.
People are incredibly good at figuring out their environment, even if it's a different environment from the one they grew up in. But if the environment isn't consistent (read, "the math is isn't very good") you can tell intuitively.
That's why a good physics model is important.
Re:Don't need to be that exact (Score:5, Insightful)
Unrealistic suggests that it doesn't behave as in the real world -- but that doesn't mean it isn't modeled on the same principles (acceleration, momentum, etc.) And you still want to simulate it consistently; it should "feel" right.
But an unstable computation method can "blow up", regardless of realistic or unrealistic "physics."
Consider:
Jump pads in games like Quake or Unreal are "unrealistic". But they are modeled at least partially on physics. But to make them work right, in all their unrealistic glory, the computation method must be stable.
If it wasn't stable, then you might something like:
- Multiple, successive jumps on one would lead to a "blow up" where the player would be wildly, and unexpectedly shot through the roof and to the outer edge of the game universe.
For both realistic and cartoon physics, you need accurate and stable computation methods.
Re:Don't need to be that exact (Score:2, Informative)
My background is in physically based modeling
in computer animation, so here is what I know:
The integration scheme can have such a strong
influence on the stability of the system that
it can mean going from an integration timestep
of a microsecond to a hundredth of a second.
That's a speedup of 10,000. Generally, the
finer the spatial resolution of you simulation
(how fine your cloth mesh or fluid volume is),
the faster a timestep you need.
The brief description of the book cites the
Runga-Kutta method as a preferred technique
over basic Euler integration. The former
is a fourth-order method, the latter a
first-order method. Three orders of magnitude
is nothing to laugh at.
The big breakthrough in cloth deformations came
because Witkin and Kass figured out how to
simulate cloth with a large timestep (they use
implicit integration techniques). Jos Stam
did some nice work with real-time fluids that
relied on a semi-Lagrangian integration scheme
with a vorticity term to undo the artifical dissipation caused by the coarse numerical
simulation.
Greatest game of all time... (Score:2, Funny)
Is it just me, or does that describe Pong perfectly?
Note: Greatest game of all time referes to the classic version, 2 controls, 1 console, 1 tv, 1 wasted childhood.
Grand Prix Legends (Score:2, Interesting)
It's still one of the most popular games in the driving sim community, with new mods and graphics appearing almost daily, but in the end it's the physics that draws people in. Yah it's hard to drive, but it should be hard to drive, and once you learn it, you'll never look back.
i just bought this book online.... (Score:3, Informative)
i read thru the sample chapter [here] [oreilly.com] it's all about particle physics. i was quite impressive, i enjoy the *conversational* style that most o'reilly books have.
i implemented all of the examples in java using java3d. [j3d.org]
i hope the book meets my expectations....
Producing position from LatG, LongG, and FwdV (Score:2)
Suppose you have a device that records lateral acceleration, longnitudnal acceleration, and forward velocity, with 100 samples per second, and stores them in a text file, one sample per line, one value per column.
Given the file parsing routine is a gimme and thus provided the values for elapsed_time, LatG, LongG, and FwdV, produce a function that will return the current X and Y co-ordinates of the vehicle, so that its ground track can be represented in a diagram.
Anybody got any good sources of information (or better yet, an existing library) for how to do this?
No, this is not an exam question.
DG
Re:Producing position from LatG, LongG, and FwdV (Score:2)
Re:Producing position from LatG, LongG, and FwdV (Score:2)
My attempts at reproducing this from my old numerical methods textbook produced unrecognisable squiggles
Assume the start position is the origin. Can you post (or link to) example code?
.
Velocity Verlet algorithm (Score:2)
The VV algorithm has a lot of advantages: it's simple, stable provided dt is small enough, and unlike straight Verlet is self-starting given an initial velocity set.
Eric
Aha! I think I just made a breakthrough (Score:2)
The acceleration values I have are taken _with respect to the vehicle's axis_ not the world co-ordinates' axis.
So I somehow have to translate the co-ordinate systems before I can apply the acceleration to the vehicle....
Any ideas on how to do that?
.
Re:Aha! I think I just made a breakthrough (Score:2)
If yes, it's just a bit of trig. You can do it two ways: keep the positions/velocities/accelerations of your vehicle in world coordinates or keep them in vehicle coordinates. I'd highly recommend the former: I assume that the forces on your vehicle are a collection of ones generated internally (by an engine, for example) and externally (by collisions with other moving objects, gravity, etc.) Only the former will need to be converted.
If your vehicle is on a plane (such as a car on a flat surface) it's easy. Define an angle theta which is the angle between the world xaxis and the direction your car is pointing. Then the components of your vehicle's acceleration a are just a(x) = a*cos(theta) and a(y) = a*sin(theta). (This assumes no slipping, of course.)
In 3-d, it's a lot easier if you have thrust only on one axis. (I.e., you have a cylindrical rocket with an engine in the tail.) This lets you ignore roll and then you only need 2 angle variables, theta and phi (aka pitch and yaw): phi runs between 0 and 2*pi and theta from 0 to pi. (Convince yourself that this covers the sphere- it does.) The conversions to take an acceleration a and two angles to cartesian (xyz) coordinates are just the usual ones to convert from spherical polar coordinates to cartesian
If you want thrust coming from any axis at any time (aka spaceship with side thrusters), you'll need to include roll. I'd have to go look these up- they're hairier.
If your vehicle is not rigid, let me introduce you to the wonderful world of constrained dynamics. I've got lots of references. (Constrained velocity Verlet= RATTLE, another of my advisor's algorithms.) Hint: if you don't know what I'm talking about, don't go this road! It's far more CPU intensive and the code is uglier.
Eric
I think we're getting somewhere... (Score:2)
Soooo then... how to determine the theta angle, given that there is no compass on the vehicle?
I don't think I've defined the problem clearly enough:
Imagine you have a car, parked on a flat plane of infinate size. The car is stationary, at the origin, with the nose aligned with the Y axis (so, for the moment, the car axis and the world axis are aligned)
Inside the car is a pair of accelerometers (one along the car's x axis, the other along the car's y axis), and a speedometer (which provides car-y-axis velocity) The car is then driven around in a path, while the accelerometers and speedometer record values at a fixed sample rate.
Given the resulting data stream, and assuming no slip, give the stream of world (x,y) coordinates that correspond to each car (x-accel, y-accel, y-velocity) coordinate.
Seems like we're modt of the way there...
.
Re:I think we're getting somewhere... (Score:2)
You can fake the compass (see below) but you need 3 instruments for 3 degrees of freedom.
For a generalized rigid body in 3-space, you have six degrees of freedom (x,y,z as "external" coordinates, rho,theta,phi (roll, pitch, yaw)as "internal"), so you'll need *6* accelerometers.
For your car, you have x,y and theta, so you'll need 3. You've got 3 instruments. X,y are fine since you have accelerometers for them. The speedometer could be used to back compute the current theta- you'll have velocity given by that (v) and you'll have computed v(x) and v(y) using the accelerometers, so again v(x) = v*cos(theta), but this is really clumsy. Better to just have the position described by x,y and theta. Note: if you have to do this inverse trig functions are usually really, really slow unless you have a good math library. (No, the standard math libraries in any language you care to name are *not* good.) Consider using a lookup table if absolute accuracy isn't needed.
Is this a real world problem? You seem to be thinking about this in terms of engineering rather than as a simulation. If it's just in a computer just track 6 position, velocity, acceleration and force variables (1 for each DoF) and be done with it.
Eric
Re:I think we're getting somewhere... (Score:2)
Math and processor time are cheaper than sensors, especially things like electronic compasses and high-res, high-sample-rate GPS.
.
Re:Mmm. Dead. (Score:2)
The good news is that I only have to do it for 30-60 second stretches.
I've also heard that one can correct somehow the wander/error from the integrated acceleration values by examining the forward speed value (which is produced by a separate sensor) - ie, work out the velocity from the accelerometers, and then compare the magnitude to the forward speed sensor, and correct the ground track from that. I haven't a clue on how that works, but I've seen evidence that it can be done.
As for what the project is... see farnorthracing.com
.
Decision Making (Score:2, Interesting)
However, in modern 3D-type games, it's important to pick and choose where you spend your time coding in the physics. In a racing game, it's a lot more important to spend time making sure the cars handle correctly than how realistically the trees sway in the background.
Unfortunately, there just isn't the time to make everything about the game perfect, and it's sad to see when a program has missed it's spot because of delays in implementing useless features.
Re:Decision Making (Score:2)
In my new game the exact opposite is true.. I really hope Ultra Mega Pine Sim is a success..
more fun blowiung up stuff with accurate physics (Score:3, Interesting)
I want a FPS that lets you blow holes in walls, accurately representing physical damage from weapons. Imagine Counter-Strike with realistic bullet physics: ricochets, windage, and weapon recoil that isn't predefined.
Hacking physics though, now that's a job and a half: figuring out a quick and dirty method of approximating the complexities of the real-world, and still have it look natural, making it look like a real environment filled with objects that have familiar properties and behaviours. And then blowing them up, REAL GOOD.
articles on physics & collition detection etc (Score:2)
Re:articles on physics & collition detection e (Score:2)
Tribes 2 (Score:2)
Re:Tribes 2 (Score:2)
Different Constants (Score:2)
There was a good article a while back in one of the mags (Scientific American?) i get about a team putting even more physics into games. If you shoot someone in the shoulder, they spin a bit etc. They were trying to make bullet hits look more real (as in reaction not gore). Anyone have a link?
Must be available as a library (Score:2)
These functions are based on laws of physics, and should be the last thing to be reinvented.
Game development as a whole will be of a far higher quality when games don't have to be developed one molecule at a time.
Games aren't about realistic physics (Score:4, Redundant)
I remember reading an article with a game developer a while back, who pointed out that the key for physics in a game wasn't realism, but consistancy.
He was developing a racing game, and says in order to make the game more fun, he had to sink the center of gravity for all of the cars several feet below the pavement, so that the cars wouldn't tip over when making hi speed turns.
As long as all the cars behaved the same way, it didn't matter that you were "cheating".
When playing your game, the user is entering your world, and learns a new set of rules. As long as you present your set of rules as consitant, it doesn't matter if they don't correspond with how things behave in "real" life.
Captain_Frisk - wannabe game designer.
Re:Games aren't about realistic physics (Score:2, Insightful)
But, guess what - even if your computer game has a G that would crush humans, or elasticity that makes super balls look tame, or centers of gravity below the pavement, it still needs to be CONSISTENT.
And being consistent means modeling real world physics. With tweaks.
If you don't model real world physics properly though you're going to end up with erratic behavior that will either lead to frustrated players or exploitation by players (which often trivializes the game).
And while I never thought about it, now I understand the purpose behind some of the abysmal math courses I took in college. I guess it's a good thing I don't do game coding, since I certainly don't recall much at all from those courses. (Another reason why math profs should come out of their theoretical world and mention real world uses for some of the stuff upon occasion).
flashbacks to highschool (Score:2)
I'm reminded of folks in high school who would get hot under the collar arguing that the Arduin rules for magic and hit points were more realistic than the D&D versions, or the realism of different types of dragons . . .
hawk
Forgotten downforce? (Score:3, Informative)
A very simple (*) way to model downforce is to drop the centre of gravity of the model so that it is below the ground. Other variables such as tire grip also have to be changed as well but these are generally constants.
(*) Downforce changes with vehicle speed so this is a very simple model.
Chris Hecker's Physics tutorials are FREE! (Score:5, Informative)
provides an excellent, and free alternative to purchasing a weighty tome on the subject. Chris covers the details of rigid body mechanics in a thorough, but light manner.
I went to a physics lecture at GDC, the most memorable part of which was Chris saying:
"Here's how it's going to go... you're going to write your first rigid body dynamics simulator. You're going to simulate a cube dropping onto a plane. You'll run the program, the cube will drop, hit the plane... and disappear."
So, so true.
Carmageddon (Score:3, Interesting)
Excepting the possibility that the N64 version is completely different from the PC version, you are completely clueless. Carmageddon, of ALL the games you could have chosen, was a pioneer in game physics. It was the very first game that I played that had a real rigid-body simulator built into the engine.
Say what you will about the gameplay, or the physical settings (gravity was too low), but you can't say it had sucky physics. The cars and environmental objects interacted in an incredibly realistic manner. It was miles ahead of Re-Volt in that department.
Games vs. Simulations (Score:5, Interesting)
On the other hand, when I play a 'simulation' the physics are quite important. The best physics I've found in a sim are in a 3-year-old game: Grand Prix Legends. You're racing 1967-era Formula One cars, which means skinny tires, no downforce, high powered...which is a combination for difficult driving. But the physics engine is spectacular: you touch the gas when in neutral, you can feel the torque twist the body of the car; each wheel has its own model; touch the gas a bit to hard in a corner and be prepared to swap ends of the car, etc., etc.
The graphics are what you'd expect for a 3 year old game, but a dedicated community has sprung up to support the sim with everything from replay analysers [bip.net], new tracks and graphics [sportplanet.com], and even a movie maker! [racesim.net]
It seems that if you make a sim with good enough physics behind it, the fans of it can create new 'eye candy' to keep the sim looking good. But if you have crappy gameplay (see: Andretti Racing) and good graphics, the game will quickly be relegated to the bargin bin when something prettier comes along.
-Mark
Re:Games vs. Simulations (Score:2)
Who wants realistic physics? (Score:5, Insightful)
And in *any* game where people jump, realistic jumping becomes completely pointless. People want to be superhuman. Imagine quake with realistic physics....
Realism is not the high mark of games in all aspects, that is the whole point of games, to escape reality...
Re:Who wants realistic physics? (Score:3, Insightful)
It is true that in some games -- a combat flight simulator, for instance -- one design goal would be to achieve the most realistic physics possible. The average kid popping quarters into an arcade game isn't looking for realism, but some folks certainly will.
However, I think the importance of _self-consistent_ physics is quite critical. You can invent your own set of "physical laws", which may be similar to those we are familiar with (ie, with moon gravity instead of Earth gravity) or completely and utterly different (ie, with Matrix-like time and space distortions or a Tolkien-like world replete with magic). However, the world you put forth should appear at once both plausible and self-consistent. Indeed, knowing real physics and the numerical methods to treat it would certainly help game programmers in their own constructions, if only by serving as an intricately balanced example which can serve as a launching point for their work.
Bob
Re:Who wants realistic physics? (Score:2)
Well, I occasionally want realistic physics.
It's been a long time since I've run a real R/C car, but I've played Re-Volt a lot. It's fun.
You're getting to do something that you wouldn't normally be able to. This is especially true with Re-Volt. You get to race some nice cars, over some really wild race courses, with a point-of-view right over the car itself. No worries about charging batteries either.
I think realistic physics adds a lot to the game. Learning how to handle the different surfaces. Learning how to bump off the wall just so without flipping your car. Learning how to power-slide. I would have ruined a dozen real cars just trying out jumping and stunts.
It helps that the game uses R/C cars instead of real ones. Because of mass-scaling laws, they have a much greater power-to-weight ratio than full-size cars. That adds a lot to the fun factor.
And maybe realistic physics would ruin other games, like Half-Life. Well, if you want super-jumps, fast running and so on, let's make a game with armored mechas instead of humans. You can have your rocket-jumps and realistic physics too.
Quake II low gravity level (Score:2)
Now thats physics
Re:Quake II low gravity level (Score:2)
how about human motion? (Score:2)
In my opinion, the most difficult aspect of writing a good 3D game is coding complex physics
IMNSHO, getting good human motion is the hardest. Sure, EA does great motion capture for their sports sims, but where else do you see this in the industry? Download the Wolfenstien single player demo and see how stiff the models look (especially in the intro).
I think getting realistic physics is important, but, since most of it can be reduced to math anyway, GHz machines and loads of memory, combined with good programming, should be able to get it right. Making motion look good is far more important to my enjoying the game, and much more difficult.
On a side note....
Has anyone else noticed how this seems to be what sets WETA's effect in LOTR apart from the rest? Instead of generating a digital army, they film a bunch of guys walking in armor, then copy/paste/randomize to make a realistic hoard of warriors.
The cave troll, while the rendering was supurb, was entirly motion-captured. They had some actor plodding around with a big stick and ping-pong balls taped to his joints. They seem to understand that they can make everything look perfect in a still image, but the motion will still look fake.
Basing a whole game around the physics (Score:2, Insightful)
Working out the forces of objects (Score:2, Interesting)
Actually, the game is not working out the forces of each object. This is why most objects in 3d fps games are static. Beyond basic collision detection, there is no interaction with the objects. If there are interactive objects in your game, the math involved in calculating the physics of a 3d pack of cigarettes or a 3d can of cola would not only take an enormous ammount of coding to bring to light, but also put undo load on the CPU.
When we worked on Ghost Recon, one of the big problems with physics involved calculating the way the trees swayed in the wind(believe it or not). Part of the solution involved going from multiple wind directions to a single one. The users wouldn't notice it. Heck, we could have made the trees static, thus relieving the system of about 40% of it's performance hit, but we wanted some level of realism in the background and atmosphere.
One thing great about this book (Score:2, Insightful)
The book is a good reference to have. To me this would be good to have because I already "learned" all of this, but like most don't remember all of it. Having all these equations right in front of you will enable you to remember everything swiftly and apply what you need to.
Like most O'Reilly books, this is a good reference to have, and I think it should be bought by people that already know most of the basic physics stuff.
LordOfTheRingBound? (Score:2, Insightful)
The book is not ring bound because it costs 25 quid (= British Pounds).
'Twould be far too easy to stick it through a photocopier or scanner if it were.
Not having seen the book... (Score:2)
If it is well bound (ie, with sewing, cloth, hardback, etc), then cut the pages out and photocopy them, then ring-bind it.
Now, I am not one for destroying books in this manner (or any manner - I love books), especially such an expensive one - but if you really need ring-bound books...
Cartoon Physics (Score:5, Funny)
I know this is a joke, but... (Score:2)
and that's not new (Score:2)
hawk
Physics? Yes. Game development? No. (Score:2)
The trick is coming up with a way to seem like you're doing much more than you really can. The book gives little help there, as trickery and non-traditional techniques can buy you a lot more than just implementing standard mechanics.
Re:Physics? Yes. Game development? No. (Score:2)
Do you have any links/books/info on the "trickery and non-traditional techniques" that game developers might use?
--Noah
My favorite example (Score:2)
My favourite for a long time has been Austin Meyer's X-Plane. X-Plane uses an engineering process called "blade element theory" to approximate the true behaviour of an aircraft in flight. And it does this fairly well; I think X-Plane does the best job of any of the PC-based sims at mimicing the actual feel of the aircraft.
X-Plane doesn't have the "eye candy" of MSFS-2002 or any of the Flight Unlimited series, but as far as accurately modeling flight physics, X-Plane is head and shoulders above the competetion.
Runge-Kutte? Give me a break! (Score:3, Informative)
Runge-Kutta is a complex method for quickly and accurately solving differential equations by numerical means. It is used instead of simple Euler iteration because it is equivalent in speed and gives much more accurate results. It works by adjusting the timestep dynamically to skip over regions where the system is changing slowly, and to integrate more carefully when the system is changing quickly.
This is all well and good when you are trying to do something important, like simulating heat flow within in a heatsink. But for simulating the orbits of planets around a star, for example? What a waste of time! The orbit is elliptical, so just simulate a freaking ellipse!
What about space missiles? Do you need Euler integration? No! There is a closed-form solution to the linear acceleration problem -- it's a quadratic. This procedure does not give low error. It gives zero error.
I read this guy's articles several months ago. I thought he was off his rocker then, and I still think so now.
Re:Runge-Kutte? Give me a break! (Score:3)
That's only true in a two-body system.
Only if you assume a flat earth with constant acceleration at all altitudes - which is an incorrect assumption when you're trying to model intercontinental ballistics.
Apparently, your soon-to-be degree in physics doesn't imply a degree in common sense.
Re:Runge-Kutte? Give me a break! (Score:3, Insightful)
Even if the gravitational force were extremely strong, it wouldn't make much difference in space battle. You still point the missile at the enemy and shoot it. You, the missile, and the enemy are all accelerating toward the sun at equal rates. The fact that a G-field is present makes absolutely no difference, since the field is uniform, at least when you are quite far from the sun and the spacecraft are relatively close to each other. In a fun game, the craft will not be far apart, since it's not much fun to fire on an an enemy when you can't see the pretty explosion.
Look, I'm going on and on about a specific example, when my real point was much more general. "Realistic" behavior of objects can be very closely approximated with very simple methods. The player will not know the difference. Problems such as integrations "blowing up" can be easily avoided simply by looking for the blow-up and correcting for it.
Re:Runge-Kutte? Give me a break! (Score:2)
Ok. Well, I had taken this part somewhat as a given. "Press left go left" is so simplistic I hadn't even thought of it. I've written a few space shooters (with graphics so bad I'm embarrassed to mention it), and the various objects in the universe were modelled with the following properties: mass, velocity (vector), position (vector), angular momentum (vector), moment of rotational inertia (assumed to be isotropic). Spacecraft in this model have linear thrusters that can change the linear momentum -- i.e., they produce a force line that passes through the center of mass. They also had rotational thrusters which provided torque (force line perpendicular to center of mass). In fact all forces were calculated relative to the center of mass. Projectiles impacting the spacecraft produced linear and angular accelerations which were quite easy to compute. To be more complex than that seems like a waste of time.
I never ran into problems with this method. I integrated four times per frame, and it worked quite well. Actually, I've never played a space shooter that really took account for angular momentum. Once you got spinning out of control in my stupid little game, it was quite difficult to get back into a sane orientation :)
Re:Runge-Kutta? Will you be getting degree? O my g (Score:2)
Not quite sure how to take your comment on my degree :) I'm also getting a degree in CS so it's a lot of juggling to be doing. I'm putting the priority on CS.
The results are what matter (Score:2)
So there I am trying to solve a ballistics problem for a game. I need to drop artillery shells on target, based on launch speed, required horizontal distance and gravity, but not, thankfully, air resistance or other accelerations. We need this to work right, but more than that, we need it to work quickly for an imminent product demo, so a co-worker is thrown at it as well. He has his Halliday and Resnick Fundamentals of Physics Extended Third Edition, and a couple of years of college maths.
So we get to work. I do a quick napkin calculate and can solve for the range based on the speed, angle and gravity, but I can't figure out how to solve the equation for the angle. It's fairly easy, but I'm an absolute duffer at maths (it nearly dropped me out of college). My coworker has started right, trying to solve it for the angle.
Five minutes later, I'm done, and I mean done. I'm dropping shells within spitting distance of the target. "Oh, you solved it then?" asks co-worker. Heh, not exactly. I'm pumping angles into my napkin equation and doing a bsearch until I get a distance that looks close enough.
Coworker is outraged! It's inefficient, he claims, which is technically true, but it's a few iterations happening every few seconds at most, which isn't even worth our time profiling. It's not perfect, which is also true. But our engine is using cheap and nasty "X += dX * dt" anyway, so even a perfect calculation wouldn't be accurate.
My points: it's hitting the target. We hit the time target. It's a game.
Sure, physics has a place, and it's aesthetically appealing, but as long as you get the results that you need, the method isn't important. The games that you think have great physics? Probably fudged nine ways from Sunday to make them feel great.
Realism and such... (Score:2)
The important thing this book (I assume) lets you do is generate better MODELS. These models can be parameterized on all sorts of things. The outcome doesn't have to be more realistic, but the interactions will be more consistent and reliable. In this way, the interactions of the forces (even if gravity is half or what it is normally) can still be realistic.
A course in mechanics (Score:2, Insightful)
"Realistic Physics" (Score:2)
What's that you say? But this whole post is about how you can do it? Nope sorry, but I don't know of any games today that really model what is going on in terms of 3D solid mechanics. Once one body interacts with another the calculations get staggering complex. Likewise do you really think that the flight sim calculates the flow around the aircraft to get it to behave right? Of course not.
What most games actually do is model everything as a point mass and then add a handful of other parameters to take into account solid body rotations. Collisions and other more complex events are handled with simple rules of thumb. Or in other words they are fudged. Provided they are fudged well it doesn't really matter. This is what many simulation games do (like Terminus). If you are very lucky they may actually calculate the stall of an aircraft using bernoulli's principle at a few key points. However it far easier to supply a stall angle and stick with that.
So when we talk about "game physics" keep in mind that some of the best game physics of all is completely fictitious. It just has to look and feel right, it doesn't have to be right especially when being right would take way to much processor power.
Lara Croft (Score:5, Funny)
Why game physics is hard (Score:3, Informative)
As someone else pointed out, there's a straightforward way to approach game physics, based on what you learn in a first-year dynamics course, and it won't work. Free flight is easy. Contacts and collisions are hard.
Detecting contacts between objects is complicated, but well-understood. There are several free collision-detection engines available, and many research papers. The time bounds are quite good; only slightly worse than O(N) with the better algorithms. Writing a collision detection system is a big job, but the theory is tractible.
Taking appropriate action when you detect a contact is the hard part of the problem. Bouncing balls are easy. Multiple irregular objects with multiple contacts, slipping and sliding, are hard. Most current games simplify their collision geometry down to cubes or spheres and botch the hard cases ("But my sword went right through him and he didn't even notice!") The latest generation of games is just starting to get contact right. In another year, correct contact handling will be a "must-have" for commercial games.
If you simulate contacts between objects with a spring and a damper, you run into numerical stiffness during integration. Soft objects at slow speeds will bounce fine. In a hard collision, the forces become huge for short periods. The simple integration algorithms will result in huge errors, and the objects will go flying off into space.
If you simulate contacts between objects as impulses (an impulse is an infinite force applied for zero time, but with a finite energy transfer), two objects bouncing off each other will work great. More than one contact per object doesn't work too well. Resting contact doesn't work; objects may fall through each other. And everything bounces like it's a pool ball, because all collisions take zero time.
If you try to do everything with constraints, resting contact works. But combinations of sliding and resting contact result in wierd corner cases that are hard to get right. Trying to solve contact, rather than simulate it, leads to static indeterminacy. (Think of a table with four legs, slightly different in length. How the table behaves is very sensitive to small changes in leg length. Numerical solutions of multipoint contact problems become similarly sensitive). This is the approach Baraff preaches at SIGGRAPH, but few others have been able to implement it.
After a few years on the problem, I developed Falling Bodies [animats.com], which successfully solves this problem well enough to simulate a human figure falling down a circular staircase. It can be done. I hammered through the spring-damper problem by using unusual and robust integration techniques. This is computationally expensive, but sound.
If you're developing a commercial game, and need working physics, go with the Havok [havok.com] engine. They have a rigid body engine, a soft-body system, and a specialized vehicle simulation engine. (Yes, vehicle physics in games typically has fake components. In most racing games, the tires are impossibly good and the vehicle CG is impossibly low. But you need a real physics engine to fake it properly.) It's not cheap, but you're not going to solve this problem in a few months. Major developers have blown years on this problem and failed. Trespasser, from Dreamworks, went down the drain that way.
Simulation vs Games (Score:2)
Not inaccurarte and unstable (Score:3, Informative)
This is only true if you're simulating a standalone system (like the orbiting planet example). In real games, the player is constantly pressing the controller, collisions are occurring, and the "AI" is making decisions. Stepwise integration makes perfect sense in that case. Calling it "inaccurate and unstable" shows a lack of game development experience.
Fantasy is better than reality (Score:2)
Better getting a comp methods physics book... (Score:2)
Don't forget ... (Score:2)
Collision Detection (CD), and more importantly Collision Response (CR) determine the "feel" for your game. You can have the most accurate physics in the world, but if your CD/CR sucks, chances are, you're bringing the game down too.
Check the archives of Game Dev Algorithms [sourceforge.net] if you want more info.
Re:Carmageddon (Score:2)
Re:Carmageddon (Score:2)
The N64 version sucked, bad, as far as physics. That is what the original poster was complaining about.
Re:throw physics out the door... (Score:2, Insightful)
Even on games where there doesn't appear to be any need for modular physics, there will always be some mod author that sees a need. Say you are writing a racer, you might think that the physics should be fixed to real-world physics, but the mod author that wants to write a 'dune buggies on the moon' mod, is going to disagree with you, so keep it modular :)
Re:throw physics out the door... (Score:2, Insightful)
I think accurate physics MUST be present in most motion-oriented games so that the control feels more natural (i.e. feels like what would happen in THIS universe). You can change masses, gravitational constants, whatever, to make objects in your world to WHATEVER you want them to do, but F=ma should still apply
Re:throw physics out the door... (Score:5, Interesting)
I think that I've seen one game (whose name escapes me atm) that actually got it more or less correct -- and I think that was just a game engine quirk that caused it.
various rules of thumb (Score:2, Interesting)
Another pet peeve i have is that a lot of these sort of things never really mention one killer point. When computing whatever delta t for updating a scene, it is best to use a moving average of the last n frames (i use 32, kept in a rotating ring buffer), because that keeps an unusually long or short frame from fucking up any calcultions.
Re:throw physics out the door... (Score:2)
Re:In defense of Carmageddon... (Score:2)
I loved pondering... "OK, so I need to get the speed up powerup and hit this ramp at such a speed at this angle to bounce off the wall of the building and fly JUST over the tower to get that platinum power up and land on the building over there."
Re:Great... (Score:2, Informative)
In the summer i took a numerical methods course using "Introduction to Numerical Methods and MATLAB: Implementations and Applications" [amazon.com] by Recktenwald. If you can use procedural languages, you can read/write Matlab scripts. I'd give the link to the course website, but the prof changes the password every term; it's a damn shame, too. He's a fellow of the IEEE, really smart guy. Had good course notes.
Re:Red Faction (Score:2)
Why? If somebody does something stupid and they get stuck it's their own fault. That's how it is in real life, why should we expect anything different from a realistic game? Otherwise you have to define what can and cannot be destroyed, and you end up with something just like the "deformable" terrain we currently have in some games, except it's got a whole lot of unnecessary math chewing up your clock cycles.
Re:on numerical integatration in programming.. (Score:2, Informative)
calculus course and then proclaim themselves
experts on slashdot.
First of all, Simpson's method does not
create an "exponential polynome." It models
a curve locally as a parabola.
Second, this method is useless in many situations
where one integrates over time. Simpson's rule
is designed to find the area under a curve.
Yes, distance is just area under a velocity
curve, but you are not given the velocities
a priori. You have to solve for them on the
spot, and even worse, velocities can be
influenced by the current position. In fluids
and soft-body deformations, things can get
even uglier. Some of the better methods for
numerically integrating through time involve
estimating the next values in time and solving a
system of equations using old and new values to
get a more accurate result (very hand-wavy explanation).
Re:Halo - worst physics I've ever seen (Score:2)
It's just you.
When you're in the jeep, look for the blue carat ^ in the middle of the screen. What makes the jeep so difficult to drive at first, is that arrow points to where your jeep will go, irregardless of where your wheels are pointed. If you grok that, handling the jeep is just 2nd nature.
Cheers