Skip to content

Realistic Physics#96

Draft
Cedric-Boucher wants to merge 4 commits into
ThalesGroup:mainfrom
Cedric-Boucher:realistic-physics
Draft

Realistic Physics#96
Cedric-Boucher wants to merge 4 commits into
ThalesGroup:mainfrom
Cedric-Boucher:realistic-physics

Conversation

@Cedric-Boucher
Copy link
Copy Markdown

This PR is intended to make the game physics realistic. Currently it is a draft PR because it is not finished yet, but this also shouldn't be merged directly into main once it is complete. What should most likely be done once the changes are complete, is to add a way to select which physics mode to use for the game. IMO this is preferable over a separate branch of the codebase, as there would only be one codebase to be updated, rather than having to occasionally update a second branch of the code just for different physics.

@Jie-F
Copy link
Copy Markdown
Contributor

Jie-F commented Jul 10, 2025

This is a really interesting idea for a change! I'm looking forward to what other changes you add, so I can play with the altered game to see how things work.

When I first got into Kessler and developed my first agent, I originally thought you had to "hone in" on your desired heading. I was silly and thought you should start turning fast, and then slow down as you approach the target. But of course the optimal way is to just command max turn rate, and then for the final timestep before reaching the target, command a turn rate of delta_heading*FPS to get exactly there. So this change would actually make turning toward a target a lot harder, and people may try solutions like a PID controller (or just discrete calculus to integrate and directly solve for how to reach a target position and angular velocity).

I feel like this would make the game a LOT more difficult though. Not necessarily a bad thing, and perhaps there's a balance to be had. With these proposed constants, it would take a lot longer to do the same turning you could do before. In the current game, it takes 2 seconds at 180 deg/s to turn a full rotation. But with this change, having a turn_thrust of 180 deg/s/s and capping it out at 360 deg/s, if I wanted to turn a full circle and come back to a complete stop, it would take 2*sqrt(2)=2.83 seconds. So maybe it'd be better to crank up the angular accel slightly, and tune it to where it feels the best to play.

@TimArnettThales
Copy link
Copy Markdown
Contributor

TimArnettThales commented Jul 10, 2025

Agree with your comments Jie. It would be very interesting to have as an option, especially if we only have positive thrust (no retro thrusters) and no drag component. Then in order to stop you'll have to rotate. Although I've played games with similar mechanics/physics, I think it'd be almost unplayable by human players - not that they can approach the aiming of agents in the game as is anyway.

Edit: I took a look at the code so far, not that it matters that much because it will just scale it differently if it's a constant, but you could add a moment of inertia so we can have sorta-realistic-ish values for thrust, etc. Could also be extended in the future if we want to do some fun things like fuel levels and as it drops your ship mass and MOI changes ;).

@Cedric-Boucher
Copy link
Copy Markdown
Author

@Jie-F you're right about the turning rate being slower now. I hadn't thought about it in detail yet and haven't tested running the game yet so I probably will increase the maximum turn thrust.

@TimArnettThales I'm not entirely sure what you mean by a moment of inertia for realistic thrust. Maybe you're referring to... There's something I realized about acceleration a few months ago, especially in relation to cars. Due to the equation for kinetic energy, KE = 1/2mv^2, accelerating with constant power or energy rate actually means that your acceleration depends on your current speed. Although, I think this would be your speed relative to what you're "pushing against" so this may not be true in space with the way thrusters work.

Yeah, I guess thrusters push hot gas out in the same way regardless of speed, unlike a car. Nevermind then. Anyway, I'm still not sure what you wanted to tell me by moment of inertia.

@TimArnettThales
Copy link
Copy Markdown
Contributor

TimArnettThales commented Jul 10, 2025

@Cedric-Boucher

Moment of inertia is a physical property of a system similar to mass, but for rotation. In the same way that you have F = ma for linear/translational force, mass, and acceleration, you have T = Ia where T is torque, I is the moment of inertia, and a is angular acceleration. This way we can convert our applied torque (rotational force) and divide by I in order to get the angular acceleration. This is what I meant by it not mattering much because if I is constant, it just scales your angular acceleration so it doesn't matter much in our low fidelity physics/game. However, if we want to get a bit more in-depth and added something like fuel tanks that were on the wing tips (or just not centered on the center of mass), as fuel is expended your moment of inertia will decrease, meaning that the same torque will give a higher angular acceleration in the same way that an applied linear thrust would accelerate you faster with reduced mass.

@Cedric-Boucher
Copy link
Copy Markdown
Author

ah, I see. Thanks for the additional explanation. yeah that could be interesting in the future but it shouldn't matter right now. It could be a separate PR down the line maybe

@Cedric-Boucher
Copy link
Copy Markdown
Author

I just had a fun little idea:
ships can choose how many mines to start with, but there is a tradeoff - each mine increases the ship's mass while it is on the ship, which means slower linear (and maybe rotational?) acceleration. upon launching a mine, the ship's mass decreases by the mine's mass.
consequently, mines have a mass and can collide with objects. I'm not sure if it would be more fun to have them simply detonate early on collision, or just update velocities based on masses of colliding objects. Maybe a threshold below which it doesn't detonate, and above which it does!

@Jie-F
Copy link
Copy Markdown
Contributor

Jie-F commented Jul 11, 2025

Haha that would be interesting!

What if we made a Kessler fork together with a bunch of fun crazy stuff? We could add gravity between all objects. Make the physics as accurate as we want. Also we could make asteroids also collide with one another, but elastically so they all bounce around.

I do feel a lot of these ideas are outside the scope of the mainline game though, and it wouldn't be compatible. I don't think it'd be as simple as having a switch toggle between them, especially when the interface is changing (turn rate vs turn thrust).

And by forking and developing it separately, it would have a lot more freedom to deviate from the base game. I'd be willing to help with that as well if you want

@Cedric-Boucher
Copy link
Copy Markdown
Author

that's fair (about not being able to have a toggle due to changing interfaces)

we could just make a fun fork then. Then anyone interested could switch to the fork if they want to play around with it. They would have to change some parts of their controller due to interface changes, but to be fair they would need to change their controller anyway for the different physics

@Jie-F
Copy link
Copy Markdown
Contributor

Jie-F commented Jul 11, 2025

Yeah I think that's the way to go! I feel the purpose of this repo is to have a stable and well-tested game for the competition, and it's preferred to just have one set of rules in the game. Having alternative physics could cause confusion for the contestants.

If we make a fork, then that could have much faster-paced changes with much less of a review process, and there's a lot more freedom to experiment around. And if any changes are really good, they can always be merged upstream into this. Again I'd love to help out and test things if you'd like, and you can email me at jie.f@pm.me

@TimArnettThales
Copy link
Copy Markdown
Contributor

Would be fun to do! We've discussed a lot of these things (especially mine and asteroid-asteroid collisions before) and a big reason why they haven't been added in the past is to lessen the calculations that have to occur within Kessler. Happy to see a fork to explore some of this fun stuff though!

I agree about making it more realistic with added mass and other properties from bullets/mines. We could also do fuel in the future too and have your mass reduce with fuel burn. Lots of fun things that can be done here. Although we haven't updated the UE graphics in a while, we could also go back to them to improve them and make things quite a bit more visually appealing with thrusters and such.

@Cedric-Boucher
Copy link
Copy Markdown
Author

Cedric-Boucher commented Jul 20, 2025

Here's a fun little preview of the physics on the ship (test_controller.py with no changes)

2025-07-20.13-23-48.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants