Question

Inertia and Friction Question

Asked by: CoolAzura

I am making a game that has a 2D interface and I would like to know how to make it so I can implement Inertia and Friction (When the throttle is off) and how to make it so when the throttle is off that it can turn and not move except for the way that inertia is going.

For example:
Ship is going 20 mphs in one direction and when turning has inertia applied to the corner making it almost like a curve turn.

When it has turned completely around (when throttle is off) and then they use throttle make it slow down and then start moving in the correct direction.

I will increase the amount of points up to 370 depending on how much people help.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-12-21 at 19:02:02ID21250659
Tags

friction

,

inertia

Topic

Physics & Artificial Intelligence in Game Programming

Participating Experts
3
Points
350
Comments
51

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Adding friction to collision response using impulse magnitud…
    I'm trying to add friction to my collision response. I've found one example that simply multiplies the tangent vector by the impulse magnitude and the coefficient of friction, then adds that vector to the impulse response vector before it is added back into the original line...
  2. Car physics - Tire/road friction, skidding, and turning
    I'm developing my first game containing player controlled cars, and therefore ofcourse I need proper car physics. I've got basic car accelleration and turning done, however, no skidding is currently done. Basically, when a driver drives a car at n speed and applies the brake...
  3. Curved corners on a table
    Hello, We just implemented a new look and feel for our web site at http://www.mactech.com On a Mac, in IE, Safari and Opera -- it looks as designed. But, last night, on a Windows machine using IE I realized there's a slight cosmetic issue with the top of the curved boxes. ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: nielsboldtPosted on 2004-12-22 at 07:50:13ID: 12884754

It is not so clear what you expect. Do you you want to control the ship by applying force and then computing change in linear and angular momentum.

If this is correctly you basically need a 2d rigid body simulator?

 

by: CoolAzuraPosted on 2004-12-22 at 10:01:25ID: 12886085

Yes, but what do you mean by rigid body simulator?

 

by: nielsboldtPosted on 2004-12-22 at 13:17:47ID: 12887658

a simulator controlling the motion of rigid bodies like boxes under influences of forces.

For 2d it is easy to implement:
Each body you simulate(eg a ship) is assigned a position p (vector), orientation r (float), linear velocity v (vector) and angular velocity w(float).

Assuming a timestep dt you have the following update rules

p +=  v * dt , v = a * dt = f / m * dt where f is the force working on the ship

For the orientation the equations are a little bit more complex

here we have a force f working on a point r on the body. This means that we can compute a torque om the body as T = (r - r_cm)_x * f_y - f_x *  (r - r_cm)_y. Where r_cm is the position  of the center of mass of  our ship or rigid body

Then then orientation of the body can be found using the following update ruke

r = w * dt , w = T / I * dt

where i a number that tells how much the body resist orientation. A rotational version of mass and you can play with the values.

the orientation of the body can then be found by cos(r)

 

by: CoolAzuraPosted on 2004-12-22 at 13:25:15ID: 12887714

Um, that sounds about right but it looks confusing, could you possible simplify it to were a beginner in physics can understand, also make a legend of what the variables mean because halfway through I got lost.

Also I have it updating 180 frames/sec
and the movement update is done every 10 frames.

 

by: nielsboldtPosted on 2004-12-22 at 14:58:12ID: 12888326

please tell exactly what you don't understand and i will try to clarify it

 

by: CoolAzuraPosted on 2004-12-22 at 15:39:14ID: 12888604

Both of the equations.

 

by: CoolAzuraPosted on 2004-12-22 at 15:41:50ID: 12888634

well all of equations

 

by: CoolAzuraPosted on 2004-12-22 at 16:12:15ID: 12888841

i'm gonna give a more indepth view of this.

Ship:
-Movement
newx = ship.position - Speed * -Cos((ship.degree + 90) / 360 * 2 * PI)
newy = ship.position - Speed * Sin((lastdegree + 90) / 360 * 2 * PI)
Uses x and y coordinates to determine next place it goes
This works even when throttle is off, has a slow down built in when throttle is off
When throttle is on current speed is increased to a maximum and when it isn't decreased to 0.

Except I would like it to have a sortof flight pattern as a game I played:
http://www.positech.co.uk/starminer/
Its 2d and has a nice engine for movement and I am trying to simulate that into my game.

-Turning
ship.degree = ship.degree (+/-) TurnRate
(+ for left, - for right)

Hope this helps more than my first example.

 

by: guitaristxPosted on 2004-12-23 at 08:10:10ID: 12893382

If the ship has its throttle off, e.g. "coasting", should turning it have an effect on the direction that it goes?

 

by: CoolAzuraPosted on 2004-12-23 at 14:50:23ID: 12896463

no

 

by: guitaristxPosted on 2004-12-24 at 06:31:58ID: 12899205

Okay, then the best way to maintain the ship's position and velocity is with a vector and a point.  The point represents the position, and the vector represents the speed and direction of the ship's movement.  This way, whenever your ship has the throttle on, for each time unit that the throttle is on, given the current direction, you add the vectors and have your new velocity vector.  Calculating the new position based on the vector should be trivial.

 

by: CoolAzuraPosted on 2004-12-24 at 09:37:06ID: 12899676

um, what do you mean by trivial?
and is there any equations I could use?

 

by: ozoPosted on 2004-12-24 at 10:21:28ID: 12899778

guitaristx > If the ship has its throttle off, e.g. "coasting", should turning it have an effect on the direction that it goes?
CoolAzura > no
Why not?  Is the ship completely symmetrical in its response to friction?

 

by: CoolAzuraPosted on 2004-12-25 at 13:09:23ID: 12901986

it slows down on the way that it is going when coasting.

but can turn with no effect on which way it goes until throttle is applied.

 

by: ozoPosted on 2004-12-25 at 16:12:56ID: 12902153

So what happens if the throttle is turned off while the rudder is applied?
How does turning affect the way it goes when the throttle is applied?

 

by: CoolAzuraPosted on 2004-12-25 at 16:16:13ID: 12902160

when rudder or turn is applied the ship rotates counterclockwise or clockwise, while drifting towards the position it was going before the thrust was turned off.


when throttle is applied it moves towards the current angle of the ship.
using these 2 formulas:
newx = ship.x - Speed * -Cos((ship.degree + 90) / 360 * 2 * PI)
newy = ship.y - Speed * Sin((lastdegree + 90) / 360 * 2 * PI)


these use a circle of where it is susposed to move, using the current degree or angle of the ship and where the ending point of a line will be on any part of the circle.

 

by: ozoPosted on 2004-12-25 at 16:33:07ID: 12902177

Most ships which sail in water are longer than they are wide, so that when they drift diagonally, friction exerts more force on its sides than on its ends, which causes the direction it is going to change.
Is your ship somehow different?
Is your ship a space ship?
If so, there should be no friction to slow it down.

 

by: CoolAzuraPosted on 2004-12-25 at 16:34:38ID: 12902179

Well it is a space ship, and I know that there should be no friction, but I am just making it slow down because I think it would not be a great aspect for it to keep moving.

 

by: ozoPosted on 2004-12-25 at 17:17:33ID: 12902237

In that case, it is probably easiest to use equations like
newx = ship.x + velocity.x
newy = ship.y + velocity.y

velocity.x = velocity.x*(1-1/friction) + throttle* Sin((ship.degree) / 180 * PI)
velocity.y = velocity.y*(1-1/friction) + throttle* Cos((ship.degree) / 180 * PI)

 

by: ozoPosted on 2004-12-25 at 17:39:56ID: 12902262

Unless you also want to account for the deceasing mass of the ship as fuel is expended.

 

by: CoolAzuraPosted on 2004-12-25 at 18:30:20ID: 12902324

well, I see how you get velocity, but what does velocity mean?

 

by: CoolAzuraPosted on 2004-12-25 at 18:30:58ID: 12902325

and does that account for inertia as well?

 

by: ozoPosted on 2004-12-25 at 18:37:31ID: 12902333

velocity is a vector describing rate of change in position,  I assume (ship.x,ship.y) and (newx,newy) are successive position of the ship

 

by: ozoPosted on 2004-12-25 at 18:39:15ID: 12902338

Inertia wants to keep the velocity constant.  (so without throttle or friction, it won't change)

 

by: CoolAzuraPosted on 2004-12-25 at 18:41:26ID: 12902341

well for some reason it makes my ship fly very fast and in the wrong direction

 

by: ozoPosted on 2004-12-25 at 18:43:33ID: 12902344

I think 1-1/friction was not the best way to express that, 1-friction would have made more sense.

 

by: ozoPosted on 2004-12-25 at 18:44:43ID: 12902346

Where is your ship pointing when ship.degree=0?

 

by: CoolAzuraPosted on 2004-12-25 at 18:45:35ID: 12902349

North

 

by: CoolAzuraPosted on 2004-12-25 at 18:49:27ID: 12902355

one sec i am trying to work with this.

 

by: ozoPosted on 2004-12-25 at 18:51:02ID: 12902359

Is north the same as +y ?

 

by: ozoPosted on 2004-12-25 at 18:51:59ID: 12902360

What direction is ship.degree=90?

 

by: CoolAzuraPosted on 2004-12-25 at 18:52:14ID: 12902361

no -y


North: -y
South: +y
East: -x
West: +x

 

by: CoolAzuraPosted on 2004-12-25 at 18:52:40ID: 12902362

West

 

by: CoolAzuraPosted on 2004-12-25 at 18:57:34ID: 12902369

Well I fixed the formula to work, but it still makes the ship move in the direction that it is turning even when coasting.

 

by: ozoPosted on 2004-12-25 at 19:02:47ID: 12902376

That's an unusual standard, but in that case, try
velocity.x = velocity.x*(1-friction) + throttle* Sin((ship.degree) / 180 * PI)
velocity.y = velocity.y*(1-friction) + throttle* -Cos((ship.degree) / 180 * PI)

 

by: ozoPosted on 2004-12-25 at 19:05:21ID: 12902380

By coasting, do you mean with throttle=0?
In that case velocity should remain in the same direction, and only slow by friction (which should be between 0 and 1)

 

by: CoolAzuraPosted on 2004-12-25 at 19:07:46ID: 12902384

hmm, let me think

when throttle is applied I have the current speed go up to a maximum speed.

then by it slowly goes down depending on friction.. what should I use as throttle?

Current Speed
or
Max Speed

 

by: CoolAzuraPosted on 2004-12-25 at 19:12:01ID: 12902391

ok I got friction to work, but now I need to apply Inertia

so when it turns it doesn't just turn right away but has a wide turn

for example:
When driving a car and you turn you have inertia and the car is still trying to move in the direction that it was.

 

by: ozoPosted on 2004-12-25 at 19:17:18ID: 12902395

It will have a wide turn, unless you have too much throttle.
Throttle should generally be small compared to speed.

 

by: ozoPosted on 2004-12-25 at 19:20:31ID: 12902399

Wait, what do you mean by current speed?
I don't represent speed explicitly in the equations, but you can calculate it as
sqrt(velocity.x*velocity.x+velocity.y*velocity.y)

 

by: CoolAzuraPosted on 2004-12-25 at 19:20:37ID: 12902400

oops sorry I said it wrong.

Ok I will explain:

Ship is pointing at 0 degrees when it turns to (lets say 60 degrees)
And we are using a reference point of a circle that is around the ship with the length of how fast the ship is going.

Now when the turn is applied it will go to some other points before it actually starts going at the 60 degree mark.

Tell me if you understand, if not I will try to simplify and make it clearer

 

by: CoolAzuraPosted on 2004-12-25 at 19:23:48ID: 12902405

well I already have the movement working right so no need to change that exept for inertia.

 

by: ozoPosted on 2004-12-25 at 19:30:39ID: 12902414

Starting at velocity.x=velocity.y=0 the ship will not move, no matter which way it turns, untill you apply throttle.
While throttle is applied, your speed will gradually increase.
When throttle goes back to 0, speed will gradually decrease under friction.

 

by: CoolAzuraPosted on 2004-12-25 at 19:34:00ID: 12902418

I see, but do you know how I could add the inertia?

 

by: ozoPosted on 2004-12-25 at 19:39:09ID: 12902426

Velocity does obey inertia.  It remains constant unless acted upon by a force (friction or throttle), and slowly changes as long as that force is applied.
To increase inertia, add more mass, and use (friction/mass) and (throttle/mass)

 

by: CoolAzuraPosted on 2004-12-25 at 19:42:32ID: 12902427

so in the equations it would be:

velocity.x = velocity.x*(1-(friction/mass)) + (throttle/mass)* Sin((ship.degree) / 180 * PI)
velocity.y = velocity.y*(1-(friction/mass)) ) + (throttle/mass)* -Cos((ship.degree) / 180 * PI)

?

 

by: ozoPosted on 2004-12-25 at 19:49:15ID: 12902434

Yes, although you could just adjust your friction and throttle values to appropriate values in your program, unless mass needs to be able to change as the program runs (like if you use up fuel, or pick up cargo)

 

by: CoolAzuraPosted on 2004-12-25 at 19:50:07ID: 12902435

I see, let me try these new things out.

 

by: ozoPosted on 2004-12-25 at 19:58:28ID: 12902445

It may be more clear to write

ship.x = ship.x + velocity.x
ship.y = ship.y + velocity.y

 

by: CoolAzuraPosted on 2004-12-25 at 20:02:39ID: 12902448

could you possible download a game where i got this idea from, http://www.positech.co.uk/starminer/
This is how i would like the ship to fly.
but for some reason the formula you gave me doesn't quite work out the way i would like it to.

Please try take a look at the way the ship flies in that game.

 

by: CoolAzuraPosted on 2004-12-25 at 20:04:26ID: 12902449

Nevermind
I think it works now.
Thanks a lot for your help.
I will award your points in just a few minutes.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...