Jump to content

simple rigid body problem (computer game)


h4tt3n

Recommended Posts

Hello folks,

 

I'm hoping someone with a better understanding of mechanics might help me with this one...

 

I'm coding a small two player space shooter game with realistic physics. I've made gravity work very well and fast, but I can't seem to solve some of the other problems regarding classical mechanics. (get the game here and have a look!)

 

The ships are able to tow asteroids around in strings, that are supposed to be perfectly rigid, but I can't make it work. Right now they work but are pretty rubbery...

 

So my question is: In terms of X/Y coordinates and vectors, how do you calculate the motion of an object that is attached to another moving object (the ship) with a 100% rigid "stick"? beware that these calculations also must take account for difference in mass.

 

Hope to hear from you!

 

best regards,

Michael

Link to comment
Share on other sites

So, you want it to be realistic do you? well, everything is elastic to some point. i'm guessing its a bit TOO elastic and thats why you want help on it.

 

Have you tried putting a damping factor on it? if you put a big one on it then it won't boing about so much and it you put a small one on it will boing about till the heat death of the universe. makes it more realistic too.

Link to comment
Share on other sites

Ah, pedants! :D

Ok, as rigid as it gets, then. Anyway, wouldn't 100% rigidity be possible in a computer simulation? The reason I ask is because I saw it years back in an oldie game called Thrusta - all the way back in the Commodore 64 days *sigh, memories... *

So if it could run fluently on a 1 mhz computer it has to be fairly simple.

 

Btw your ideas on rotating around centre of mass and damping are both nice -I' ve already written some code that simulates two or more celestial bodies rotating around centre of mass, but since the distance obviously isn't fixed I can't use it here. Damping sounds better. Damping something relative to frame of reference is easy:

 

Velocity Xvector *= 0.99

Velocity Yvector *= 0.99

 

or the like. But how about damping relative to a moving object (the ship)? Silly me, I just can't figure it out.

 

Michael

Link to comment
Share on other sites

If I understood you correctly then you have two masses in 2D space where one of the masses can be accelerated and you also have the additional restriction that the distance between the masses must shall remain constant. Spontaneously, I think the solution to the problem is treating the 2-mass system as one system which can move and rotate. Any force (acceleration of the ship) can be decomposed into a vector parallel to the connection line of the masses and a vector perpendicular to it. The share parallel contributes to the acceleration of the 2-body system in 2D, the share perpendicular contributes to its rotation. That should give you good if not even correct results.

 

I don´t want to send you away from here but I think for such a specific kind of question you will most likely get better answers in the Math&Physics section of the forums on http://www.gamedev.net - they had some pretty competent people in there a few years ago when I was still active there (but check the tutorials first in case your question is a common one and already answered in them).

Link to comment
Share on other sites

You are probably right about gamedev beeing a better place to aks such Q's - I'll go there and have a look. Treating the ship/asteroid system as a single object sounds right - I'll tamper with it.

Anyway I got the damping as proposed by insane alien working just fine, and thats just ok too.

 

Michael

Link to comment
Share on other sites

  • 2 weeks later...

The actual answer will depend on the shape of the asteroid and it will take at least a page of algebra to get the answer your looking for, but i'll give a quick summary of the method you should use.

 

The first step in calculating this is finding what the centre of mass will do. This is done by using the concept of conservation of momentum. Sounds like you will have no trouble with that.

 

The second part of the problem is to calculate the rotation around this centre of mass. It will involve calculating the moment of inertia of the asteroid (see first year university textbooks for this). you will also need to calculate the total initial angular momentum of both the asteroid and the ship. Then you after they stick they will have a different moment of inertia but the total angular momentum will be conserved.

 

This will not give you the answer in terms of x and y. For that you will then have to apply sine and cosine functions.

 

I hope this helps you get started.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.