• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

miles vignol

Drag/Friction

12 posts in this topic

I've got a 2D system where collisions take place and forces are redistributed to the colliding objects. Everything is great, but I wanna introduce a drag/friction component to my system. Actually, I wanna introduce a REALISTIC drag/friction component. My problem is that my game is not locked to a certain iteration cycle, that is, it might be 10 milliseconds from one update to the next, or perhaps 3, or maybe 45 -- depends on drawing speed. I'd like to figure out an equation that makes sense in this sorta system. What I currently have is: drag = pow(DRAG_FACTOR, 1 + time_frame*10); velocity = velocity / drag; time_frame is how many seconds have elapsed since my last update call. generally, it's around 0.01-0.02... the DRAG_FACTOR is currently 1.07 which stops things pretty quickly (which is what I want)... This works, but it seems a little kludgy to me. I'm also interested in limiting the velocity for each entity. Should I do it in the drag equation (sorta terminal velocity) or in the accelleration application to velocity? If the latter, what's a good technique? Right now I'm simply adding my accelleration to my velocity in an ever increasing way, then just clamping it at a specific value which also seems kludgy. Any thoughts? Edited by - miles vignol on July 23, 2001 7:08:46 PM
0

Share this post


Link to post
Share on other sites
First it''s far easier to do this is you have a fixed time frame: calculations are simpler it''s especially difficult to debug a time frame depending on a frame rate that can vary greatly depending on hardware and OS. I would suggest seeing if you can put the dynamics in a seperate thread from the rendering as in the long run it will simplify things. E.g for your example instead of using expensive functions like pow you can use simpler linear expressions such as:

v = v - k * v

As for terminal velocity, this should work with a fixed time frame: with fixed frame rate drag is a constant, and as velocity increases the amount of velocity lost to drag each time step also increases. Eventually it matches the thrust/accleration, so it cannot go any faster. With variable time frame it should still work, though it may be destabilised by a variable frame rate.

One thing you can try is using quadratic drag. I.e. make the drag proportional to v2 instead of v. This is more realistic and has the benefit that it cuts off high speeds much more quickly. It has the opposite effect at low speeds though - things moving slowly are much less effected - so it''s often best to use a combination of both v and v2. Something like (in 1D)

v = v - k * v - m * v2

0

Share this post


Link to post
Share on other sites
I think that it is a good idea of using two different friction formulas for static friction (v in [0,some threshold]) and dynamic friction (v in [threshold,inf]). Simply because formula that behave well with high speeds tend to behave strangely at low speeds and vice versa. You could even introduce a third friction term: high speeds, low speeds, static. Is is even more realistic, since you could introduce seperate dynamic and static friction coefficients, which is realisitic (it is far easier to accelerate an object already moving than one that is standing).

- AH
0

Share this post


Link to post
Share on other sites
Thanks for the input. I guess the main things I need to play with are the coefficients. It gets a little more complicated because it seems a little silly to apply a heavy drag opposite the direction of accelleration.

This is for a game that is tank based. I used to have a simpler movement scheme that felt very good, but was not very good from a physics standpoint -- collisions and forces didn''t exist well with the movement system. I''m trying to get the feel of my old movement system back using a more realistic approach that fits with the rest of the package.

I suppose I could break my drag into a weak drag (wind resistance or something) and a strong drag (ground friction). The friction component should be reduced for the direction of accelleration, I would think, but I''m not sure how. I''ve implemented a simple increase in the coef when "power sliding" (moving counter to the tread direction), but it''s all very kludgy still...

I''ll play around with reformatting by velocity equations to be more like the ones mentioned above, rather than simply recursively multiplying them... maybe something will strike me...

thanks again.
0

Share this post


Link to post
Share on other sites
If dynamic_friction_value is the value you''ll be using in your equations and static_friction_value is the friction amount assigned to a surface, then:

dynamic_friction_value = static_friction_value / FPS
0

Share this post


Link to post
Share on other sites
Sorry, I missed what you said before:

quote:

drag = pow(DRAG_FACTOR, 1 + time_frame*10);



But anyway, there''s a problem with frame-rate dependant physics. Different frame rates result in different floating point rounding errors, so your movement will be different at different frame rates. This was exploited in Quake III until a patch was released making physics entirely independant of framerate.
0

Share this post


Link to post
Share on other sites
yeah, my goal is to make the game function identically no matter what the "view rate" is. At the moment I''m cheating by breaking down large time intervals into shorter ones, but I''d like to keep this at a minimum...
0

Share this post


Link to post
Share on other sites
miles, I'm not sure why you write,

velocity = velocity/drag;

I mean, you do reduce the velocity but that really isn't a true drag or friction. That is, a drag or friction is a force that affects acceleration, and thus indirectly affects velocity. Your approach may work if you get the coefficients worked out, but is not a drag or friction force. Its great as long as it does what you want.

A true drag acts opposite velocity not acceleration.

Why not apply a viscous drag, which is like an aerodynamic drag? It may work well for a varying time step. Apply the viscous drag force along a vector direction opposite the direction of velocity over whatever time step your current frame produces. Viscous drag naturally goes to zero as velocity goes to zero, so it scales naturally.

The magnitude of viscous drag can be calculated using this formula:

  
viscous_drag_magnitude = C_d * rho * vel * vel * ref_area


Here, C_d is a drag coefficient. For blunt bodies (i.e., spheres or similar) at low speeds start with C_d = 1.0 and tweak. rho is the density of whatever fluid the object is moving in (use rho = 0.0023769 slugs/cubic foot or 1.225 kg/cubic meter for air at sea level) vel is the magnitude of velocity of the object relative to the fluid (just the magnitude of velocity in world space if the fluid itself is not moving----i.e., there is no wind). Make sure vel is consistent with your units for rho. And ref_area is a reference area, for a blunt body use the frontal projected area---there are of the object as projected onto a plane towards its front side. Make sure the units are consistent (if you use rho in slugs/cubic foot, ref_area should be square feet. If you use kg/cubic meter, ref_area should be square meters.) Drag will be in pounds if you're using slugs and feet and it will be in Newtons is you're using kg and meters.

(For units people, 1 pound is equal to 1 slug-foot/second_squared, and 1 Newton is equal to 1 kilogram-meter/second_squared----which you can figure since F = ma and the units on both sides of "=" have to be the same.)

Anyway, this approach may be more than you want to do but it might work.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on July 25, 2001 10:41:48 AM
0

Share this post


Link to post
Share on other sites
Dang.

Actually, that''s all very helpful. I''m not sure I''m gonna bother with the some aspects -- I''ll likely have a composite drag coef that gets my results rather than rho and ref_area.

My total problem is this:

I have a tank with essentially instant acceleration (no throttle). The velocity is then affected by this acceleration. I''d like to be able to specify a max speed and an acceleration amount. For example, lets say a max speed of 35 units per second and an acceleration of 10 units per second^2. I don''t want the acceleration to be linear and then just stop once the tank is moving at the max speed. I''d like it to ramp in. I also want any residual velocity from collisions or sharp turns to die out very quickly (so the tanks don''t act like hockey pucks). Unfortunately this tends to make the tank''s terminal velocity very low, so it seems I need to affect the drag/friction differently based on the direction of acceleration. Since the treads are the real point of contact, I could probably base my math on the tread speed, then apply the tank acceleration as a "childed" space or something...

It''s all a lot more annoying than I thought it would be. I''ve generalized a lot of my physics code, so I''m trying to get a handle on all the hacks to get them to be more in line with real world units and concepts. The drag system came from a simple iterative percentage loss of speed, then moved to a power function when I altered my timing code. Now I''m trying to replace it completely... The nice thing about it, tho, is that it''s accurate over an arbitrary time frame. Since the velocity is used in a drag formula, and drag influences velocity, the iteration size would seem to be important...

My head is swimming...

0

Share this post


Link to post
Share on other sites
ok, here's how it works. x=x'+v*dt+a*dt^2, dt being time increment. that's euler integration, which i assume is what you're using, although obviously without the time step. it's horrible for anything attempting to even remotely approximate real world physics, you should look into verlet or leapfrog integration, but i digress. dt = t - t', or current time stamp minus the last frame's time stamp. that would be your "10 milliseconds or perhaps 3 or maybe 45."
now, here's how you would apply the drag force as explained by graham. as you might remember, a=F/m. F here, for all intents and purposes, is the combined force acting on the object. in other words, you add up all the force vectors that you're dealing with and apply them to the object as follows(still using euler. definitely look into verlet, P* = 2P-P'+a*dt^2, it'll make your life a lot easier)

P += V;
V += A;

if you want the drag equation to work properly, you definitely don't want to put ref_area into a composite drag coefficient. it depends on which way the object is moving relative to its local space, in other words, a sheet of cardboard dropped parallel to the ground will encounter a lot more drag than a sheet of cardboard dropped perpendicularly to the ground. a simple approximation (an incorrect one, but it'll work) would be to project the geometry onto a plane perpendicular to the direction of travel and compute the area of the boolean OR of the resulting polygon set.

also, you seem to be confusing drag with friction.. they aren't the same thing.

-goltrpoat


PS - just realized that you're in 2d, not 3d.. so disregard what i said about the plane projections in regards to the reference area

Edited by - goltrpoat on July 25, 2001 12:30:05 AM
0

Share this post


Link to post
Share on other sites
I''m not really confusing drag with friction, so much as just trying to combine the two. Perhaps that''s not a good idea. My root problems are:

1. trying to get rid of velocity in undesired directions (sliding)

and

2. trying to keep the tanks from accelerating to infinite speeds.

I figured a combined drag/friction model would be able to address both of these issues.

I suppose I could ditch the drag concept and work purely with friction as a momentum stealing force. Then I could invertly relate acceleration to velocity. That''d give me a clean cap on speed with a semi natural acceleration falloff as speeds increase.

I play around with it some more (damned Diablo 2 expansion pack!) and see where it takes me...
0

Share this post


Link to post
Share on other sites
Hi!

There is an article about car physics at http://home.planet.nl/~monstrous/tutcar.html

There are also information about drag and friction.

Greetings
McMc
0

Share this post


Link to post
Share on other sites
quote:
Original post by goltrpoat
ok, here''s how it works. x=x''+v*dt+a*dt^2, dt being time increment. that''s euler integration, which i assume is what you''re using, although obviously without the time step.



There''s a problem with your equation. It should be:

x = x'' + v*dt + 0.5*a*dt^2

You were missing the 0.5 coefficient on the last term. Also, that is not an Euler integration *unless* you say that x, v, and a on the right-hand side are all from the previous time step. If you mean for x'' to be the initial starting value of x'' then the equation doesn''t represent an Euler integration. Rather, it represents an exact solution for constant acceleration, a, and in this case the v also must be the initial velocity at the start time. And dt must be measured from the start time.

Also, a minor beef. Note that I''ve capitalized Euler. Euler is a person''s name and when a method, number, or equation is named after a person the word should be capitalized. Any technical editor, book editor, or professional scientist or engineer will correct you on this. (And I am occasionally all of these.)

quote:
Original post by goltrpoat
if you want the drag equation to work properly, you definitely don''t want to put ref_area into a composite drag coefficient.
it depends on which way the object is moving relative to its local space, in other words, a sheet of cardboard dropped parallel to the ground will encounter a lot more drag than a sheet of cardboard dropped perpendicularly to the ground.



Actually, ref_area does *not* depend on the direction moving relative to the wind. Its a constant for a given shape, and it is defined based on how the drag coefficient is defined, which is independent of the orientation of the object. In fact, it is C_d that changes depending on direction of motion relative to the wind. In the case you mention, the cardboard dropped perpendicular to the ground has much less wind resistance and a much lower C_d than the cardboard dropped parallel to the ground. The ref_area is really just a constant scaling factor on drag, a convenience term that is used to convert a drag force (which has units such as pounds or Newtons) to a unitless value.

But you make a good point. If you have an object that does exhibit significantly different wind resistance (which *is* related to the dynamically changing projected area-----different than ref_area), then C_d must change for realistic drag. For some simple shapes, such as airplane wings at moderate angles to the wind, its easy to come up with an estimate (using a parabolic drag polar, possibly with an additional parabolic low-drag bucket for very low angles relative to the wind). For complex shapes (automobiles) it is not as easy.

I realize I''m going off on a tangent here, that may no longer be important to this topic. Forgive me, but I studied aerodynamics in university for 9 years and its nice to talk about sometimes, .

quote:
Original post by goltrpoat
also, you seem to be confusing drag with friction.. they aren''t the same thing.



Hmmm. Of course, a component of aerodynamic drag *is* the friction force between the air and the body and so they really *are* the same thing to a degree. There is a pressure component to drag as well and that is not friction.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
0

Share this post


Link to post
Share on other sites