Yes, but what do you mean by rigid body simulator?
Main Topics
Browse All TopicsI 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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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)
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/
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.
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.
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.
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.
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
could you possible download a game where i got this idea from, http://www.positech.co.uk/
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.
Business Accounts
Answer for Membership
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?