Implementing my own (simple) physics

Godot Version

4.2

Question

Hello everyone!

I am a computer science student who is using Godot for learning over the summer. For my next lesson, I want to implement some of my own physics integration and collision resolution. (I would ideally like to use Godot’s built-in collision detection.)

Will overriding _integrate_forces for a RigidBody3D be enough or is there anything else that I should be aware of as I get started on this task? (Specifically, I am not sure if I will need to create a PhysicsServer3DExtension to accomplish this.)

Thank you for your time! :slight_smile:

You can fully write your own force integration logic by enabling RigidBody2D.custom_integrator and writing your logic overriding RigidBody2D._integrate_forces()

I don’t know if you can manage the collision resolution though.

1 Like

Thank you for your response! :smiley: So far I have found that if you override _integrate_forces, it still manages all of the collision resolution for you, but this is a great start for the physics integration.

I also wanted to add onto the original post that if anyone simply knows the file or function where the collision resolution is done for RigidBody3D’s that it would be quite helpful. I have had a look at some of the source code files and am still lost as to where exactly it is done.

I am going to keep digging on my own, but just wanted to put that out there in the meantime!

All the CollisionObject3D nodes (areas and physics bodies) just communicate and query the PhysicsServer3D server. They don’t have any physics code.

All the 3D physics is here godot/servers/physics_3d at master · godotengine/godot · GitHub For example, the collision solvers are here godot/servers/physics_3d/godot_collision_solver_3d_sat.cpp at master · godotengine/godot · GitHub

Here’s what each physics step does: godot/servers/physics_3d/godot_step_3d.cpp at 04a530f91fc83b41112007dbd2ce02e9528df682 · godotengine/godot · GitHub

1 Like

Thank you very much for pointing me in the right direction! These links are very helpful and I appreciate your time. :grin:

I would like to continue posting here as I progress in this endeavour; please let me know if the pings are bothersome.