I made a gravity simulation with a working camera

The title says most of what I want to say, I just made it because I thought it was really cool and wanted to share it in case some people think it was interesting. It’s mostly made of spaghetti code but it’s functional

Moving around randomly (note there is a small bug with the camera that spins it around sometimes, I know how to fix it, I just haven’t yet)

Orbits, While very unstable, can actually work. (It’s very unstable because I have the gravity calculation linked to the frame count, so if my fps drops, gravity drops, but it’s fixable)

I put a slit into the sphere, Complex geometry works with this

Also, It’s completely possible to add the possibility of multiple gravitational objects, so I might do that next.

10 Likes

Awesome! This is amazing! Will it be open-sourced?

I probably will, I already have another game, so I’m really doing this because I’m bored on the weekdays

1 Like

Thanks! I can’t wait to use this. It’s going to help tons of people.

1 Like

Ok, I managed to make a solar system with it which I just populated with random objects
Which works decently

The problem, The camera is still broken on an axis, so it still whips around a lot, No idea how to fix it right now
But I’m also bored of trying to solve that, so I’ll post the game link
https://www.roblox.com/games/8158134521
It’s also uncopylocked, but, the code isn’t great because I’ve just been trying to get it to work without thinking about keep it clean.

3 Likes

damn its super cool and smooth

could I ask, how did you manage to orient the camera in that way? Just curious.

Bump, this is a good game and I still want answers.

You have to get the roblox camera script, and just before the game updates the camera you have to rotate the camera by a cframe that’s pointing to where ever gravity is (just average out all gravity vectors and that should work). And you have to make sure to unrotate the camera after the game renders in order to not mess up the camera cframe for the frame afterwards. There are a few more quarks but doing that should get you close enough.

Heh, unfortunately I’m sorta using line forces to get gravity in my game… I’ve gotten the movement down, but the camera isn’t unlocked. I’m genuinely of fan of your work and how you got the camera to move like that. I will need to do more cframe and camera module learning, then.

in that case just loop over all the line forces and add them up, and then get a cframe value based on that

2 Likes

Say, where is the camera updated in the modules?

1 Like

In the “CameraModule” script under the “PlayerModule” Script at around line 500

2 Likes