Rocket/Space Game (Was "Rigid body rotations")

A spot for all things TestTube
testtubegames
Posts: 1100
Joined: Mon Nov 19, 2012 7:54 pm

Re: Rigid body rotations

A Random Player wrote:What I have so far is give the collection of objects an extra velocity to make the total translational momentum be 0. Then we calculate the "pulling" momentum of each mass by breaking the velocities into the radial and "towards/away from center" velocities. Add together the towards/away velocities. The remaining velocities are all radial. Calculate the total... Not sure what this is called. Distance of each object from CoM * mass * velocity. Find the average rotational momentum from those, then add up the velocity removed at the beginning and the sum of the towards/away velocities to get translational.
Is this right?
Ah, I see. Yeah, dealing with the velocities instead of the forces should be fine, then.

Looking over your steps -- that does look like a way to get the right answer. Though I'd probably take a very slightly different approach -- where you can skip the 'zero-ing' of the velocities at the beginning (and adding it back in at the end).

Step 1: Find linear momentum (and by extension, velocity): Add up the momentum of all the particles. Bam. Done.

This one's pretty darn easy, there. Since we know the total momentum of the system is the same whether you think of the pieces as connected or as separate, you can just straight up add the individual vectors. An easy, quick way to find the linear velocity of the rocket.

Step 2: Find the angular momentum: Basically what you said for this step. Break down each particle's velocity in to a radial portion (pointing toward the CoM or away from it) and a tangential portion (pointing at a right angle to the CoM). {as a heads up, I think you may have been misusing radial -- that's the one that heads in or out like, say, electric field lines.} Discard all the radial parts, since they don't contribute anything to spin. From the tangential part of the velocity, you can easily get the individual particle's angular momentum (as you said, distance to CoM*mass*tangential velocity). Add up those angular momenta, and you'll get the total angular momentum of the system.

Of course, you don't just care about the angular momentum... you'll want to know the speed with which it is spinning. And for that, you'll need to know the moment of inertia of the system. (Since, just as linear momentum = mass*linear velocity... angular momentum = moment of inertia*angular velocity) So, just calculate the moment of inertia at the same time as you figure out the CoM, I'd say.

Does this make sense?

Side note: I'll be excited to check out this project when you've got a build of it!

A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: Rigid body rotations

So this is somewhat working. I've changed the physics to store groups of objects instead of single objects, to make it more accurate. (otherwise numerical errors may become problematic, especially if far from the origin.). The code is also easier, but I don't use the algorithm described earlier as much. Maybe a good thing, it was a little complicated.

Right now this has:
Somewhat of a spaceship/rocket editor. Like, you can't move/pump fuel, parts can't fall off, you can't delete parts, quote " 'currently fuel tanks act as boosters" (as a comment in the code). Though I have what I think is RCS working. But I think my numbers are somewhat inaccurate, I can reach solar escape with one tank of fuel. (fuel does run out.)
You can set keybindings for parts (control thrust with I? or O? (or both?))
Sun/Earth/Moon system (scaled down like in KSP)
Path prediction (with apoapsis/periapsis display). Somewhat.
No solid ground Nor atmosphere.

I've gotten in orbit around the "moon" already so far.
Attachments
Designing
Rocket game screenshot 2.png (152.26 KiB) Viewed 15711 times
Orbits (it appears I forgot to show the menu for it)
Rocket game screenshot.png (129.61 KiB) Viewed 15711 times
\$1 = 100¢ = (10¢)^2 = (\$0.10)^2 = \$0.01 = 1¢ [1]
Always check your units or you will have no money!

testtubegames
Posts: 1100
Joined: Mon Nov 19, 2012 7:54 pm

Re: Rigid body rotations

Cool! What did you make the game in? I'd love to see a video of the gameplay at some point -- seems like it's a pretty neat 2D KSP. (I know we'd all be excited to play around with it if you make a build, too)

robly18
Posts: 413
Joined: Tue Jun 04, 2013 2:03 pm

Re: Rigid body rotations

I concur. I want to see this and what it's coded on. The icon for the window looks somewhat familiar.
Convincing people that 0.9999... = 1 since 2012

A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: Rigid body rotations

testtubegames wrote:Cool! What did you make the game in? I'd love to see a video of the gameplay at some point -- seems like it's a pretty neat 2D KSP. (I know we'd all be excited to play around with it if you make a build, too)
robly18 wrote:I concur. I want to see this and what it's coded on. The icon for the window looks somewhat familiar.
Visual Basic. It's the only language I have that can build independently runnable exe's. For a video, do you have any way to easily do this without downloading anything?

I've added some things since the screenshots, mostly a slightly cleaned up interface and an orbital period display. Still no ground though.
\$1 = 100¢ = (10¢)^2 = (\$0.10)^2 = \$0.01 = 1¢ [1]
Always check your units or you will have no money!

exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Rigid body rotations

If you have QuickTime, you can just use that and create a screen video which you can then post to YouTube.
Nobody ever notices my signature. ):

A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: Rigid body rotations

exfret wrote:If you have QuickTime, you can just use that and create a screen video which you can then post to YouTube.
I do not appear to have QuickTime

Edit: I've found a pretty good website that lets you record things (http://www.screencast-o-matic.com/). A bit laggy, but seems it'll work fine, when I have the time to make a video.
\$1 = 100¢ = (10¢)^2 = (\$0.10)^2 = \$0.01 = 1¢ [1]
Always check your units or you will have no money!

exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Rigid body rotations

Yeah, recording does cause lag. It all depends on the memory management of your computer. For example, if you record ~TES~ (or VP), then ~TES~ (or VP) is the thing that lags, but if you record minecraft (with quicktime, that is), well, then you just get a bunch of screenshots that go along with a somehow continuous audio. A professional recording software would probably lag less, but you obviously aren't looking for professional software. Also, if there's any way for you to record audio as well, that would be good, because something I've learned from watching robly's Shocktopus video is that it just feels really lonely and pointless and boring watching a video without any sound.
Nobody ever notices my signature. ):

testtubegames
Posts: 1100
Joined: Mon Nov 19, 2012 7:54 pm

Re: Rigid body rotations

A Random Player wrote:A bit laggy, but seems it'll work fine, when I have the time to make a video.
Great! And good luck adding in ground. (Then good luck avoiding the ground with your spacecraft)

A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: Rigid body rotations

testtubegames wrote:
A Random Player wrote:A bit laggy, but seems it'll work fine, when I have the time to make a video.
Great! And good luck adding in ground. (Then good luck avoiding the ground with your spacecraft)
Well, pretty much everything is circles, so there's a really easy way to calculate that (even numerically - just push the objects apart every frame)
\$1 = 100¢ = (10¢)^2 = (\$0.10)^2 = \$0.01 = 1¢ [1]
Always check your units or you will have no money!