Skip to content

Implement get_applied_force and get_applied_torque for 3D joints#111842

Open
brainfoolong wants to merge 8 commits into
godotengine:masterfrom
brainfoolong:physics3d_joints_get_force_torque
Open

Implement get_applied_force and get_applied_torque for 3D joints#111842
brainfoolong wants to merge 8 commits into
godotengine:masterfrom
brainfoolong:physics3d_joints_get_force_torque

Conversation

@brainfoolong

@brainfoolong brainfoolong commented Oct 20, 2025

Copy link
Copy Markdown

Hey there!

Since Jolt is directly implemented and Jolt has a lot of features and improvements over default physics, the goal of Godot seems now to integrate Jolt more tightly with Godot and make it a complete replacement long term.

One thing i really miss is the control of joints and how to correctly measure them, so i am able to break them when i decide to do so.

Fortunetely, Jolt already have 2 convenient methods to play with: get_applied_force and get_applied_torque directly on a joint.

All what was missing is the bridge/expose to Godot and GDScript, which this PR does integrate.

I tried my best to follow all the rules that i've found for godot core development, please review and give feedback on whatever you decide.

My C++ knowledge is a bit rusty and also this is my first time fiddling with the godot engine core.

Hope this helps you out. Would love to see it merged, i for now work my own fork until this (or anything similar) gets merged into master.

I've not found any tests for physics what so ever, so i not have written tests for it.

Documentation (Xmls) however should be updated properly, Warnings are emitted if the feature is not supported (When on default physics).

Proposal: godotengine/godot-proposals#13422

MRP: physics3d_joints_mrp.zip

@brainfoolong brainfoolong requested review from a team as code owners October 20, 2025 11:00
@AThousandShips AThousandShips changed the title Implemented 3d joints get_applied_force and get_applied_torque Implement get_applied_force and get_applied_torque for 3D joints Oct 20, 2025
@Shakai-Dev

Copy link
Copy Markdown
Contributor

Hey there! Do you have an MRP & test builds as well so we can test this in action?

@brainfoolong

Copy link
Copy Markdown
Author

Hey there! Do you have an MRP & test builds as well so we can test this in action?

Hey, please give me some advice what this exactly is (MRP) and how i can provide that data?

@Shakai-Dev

Copy link
Copy Markdown
Contributor

Hey, please give me some advice what this exactly is (MRP) and how i can provide that data?

It's a small, minimal project which will allow us to test your features. You can just make a .zip & provide it along with your Godot build.

@AThousandShips

This comment was marked as resolved.

@AThousandShips AThousandShips added this to the 4.x milestone Oct 20, 2025
@brainfoolong

brainfoolong commented Oct 20, 2025

Copy link
Copy Markdown
Author

Hey, please give me some advice what this exactly is (MRP) and how i can provide that data?

It's a small, minimal project which will allow us to test your features. You can just make a .zip & provide it along with your Godot build.

Allright, i will create some. What build should i integrate, is a windows build .exe file enough? All in one zip file i guess?

Thanks for opening a pull request!

Feature pull requests should be associated to a feature proposal to justify the need for implementing the feature in Godot core. Please open a proposal on the Godot proposals repository (and link to this pull request in the proposal's body).

Thanks, the reference is already added.

@AThousandShips

This comment was marked as resolved.

@brainfoolong

This comment was marked as resolved.

@AThousandShips

Copy link
Copy Markdown
Member

Thank you realized my message had a typo it should have said to link to the proposal in the PR, don't know how that got in threre!

@Shakai-Dev

Shakai-Dev commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Allright, i will create some. What build should i integrate, is a windows build .exe file enough? All in one zip file i guess?

Just provide the MRP instead!

@AThousandShips

Copy link
Copy Markdown
Member

Please don't upload any builds, they can be gotten from the CI build or built manually, people shouldn't run unknown executables uploaded to GitHub

@Shakai-Dev

Copy link
Copy Markdown
Contributor

Please don't upload any builds, they can be gotten from the CI build or built manually, people shouldn't run unknown executables uploaded to GitHub

How can I get them from the CI?

@AThousandShips

Copy link
Copy Markdown
Member

They're listed as artifacts, see here

@brainfoolong

Copy link
Copy Markdown
Author

Thx for all feedback. MRP is added -> physics3d_joints_mrp.zip

@Shakai-Dev

Copy link
Copy Markdown
Contributor
swpr.mp4

This is the showcase of this PR. It looks nice :) (Sorry for the lag, may be because I have many apps open)

@brainfoolong

brainfoolong commented Oct 20, 2025

Copy link
Copy Markdown
Author

I've looked into the 2 failing checks, but i am not quite sure about both:

https://github.com/godotengine/godot/actions/runs/18650008833/job/53166436589?pr=111842
This jobs seems to fail because the sorting of things in the xml, should i implement the proposed changes from this Run?

https://github.com/godotengine/godot/actions/runs/18650008833/job/53166436573?pr=111842
Here i am out of knowledge what can cause this issues. Any advice? Is it maybe because of float vs. real_t in header and implementation? Why only linux with "doubles" fails on this?

@AThousandShips

Copy link
Copy Markdown
Member

The methods should be sorted yes, please see here

The second issue is that you are not matching the return types, they're changed from float to real_t only in the header

@Shakai-Dev Shakai-Dev mentioned this pull request Oct 21, 2025
5 tasks
@brainfoolong

Copy link
Copy Markdown
Author

My 2c in the real_t discussion: I think real_t should only be used for things that can potentially become very large (e.g. positions, velocities). Forces/torques should never become big enough for float to be too inaccurate and since float is cheaper than double I would go for float. Also, Jolt returns the results in float, so you're not getting better precision by converting to real_t anyway.

Allright, i've changed it that way.

Comment thread doc/classes/ConeTwistJoint3D.xml Outdated
Comment thread doc/classes/ConeTwistJoint3D.xml Outdated
Comment thread modules/godot_physics_3d/joints/godot_pin_joint_3d.cpp Outdated
@brainfoolong

Copy link
Copy Markdown
Author

Ups, i'm not sure if i messed up this PR. I accidentally synced master into this PR. May this be a problem?

@AThousandShips

Copy link
Copy Markdown
Member

Didn't cause any problems this time it seems but prefer to rebase instead, you can remove that merge commit using:

git reset --hard HEAD~
git push -f

Make sure to pull your branch to your local version first to make sure you drop the merge commit though

@brainfoolong brainfoolong force-pushed the physics3d_joints_get_force_torque branch from 70d5e17 to 34756da Compare November 2, 2025 10:07
@brainfoolong

Copy link
Copy Markdown
Author

@AThousandShips Thanks, seems it worked.

@brainfoolong

Copy link
Copy Markdown
Author

Is there any possibility that this get merged? The longer it takes, the lower the possibility that this can be merged without problems, i guess?

@AThousandShips

Copy link
Copy Markdown
Member

Right now we're in feature freeze for 4.6 so new features and enhancements won't be merged until after that has been released (scheduled for January)

@GarrySlop

Copy link
Copy Markdown

Hey, I am unsure if this should be a new issue or what, but the error

Condition "joint->get_type() != JOINT_TYPE_PIN" is true. Returning: 0.0 <C++ Source> modules\jolt_physics\jolt_physics_server_3d.cpp:1776 @ pin_joint_get_applied_force()

is being given when node_a and node_b is empty while trying to get applied forces.
This is pretty simple to work around, but in my opinion it shouldn't be giving errors for this.
Loving the commit so far though 😘

@brainfoolong

Copy link
Copy Markdown
Author

Hey, I am unsure if this should be a new issue or what, but the error

Condition "joint->get_type() != JOINT_TYPE_PIN" is true. Returning: 0.0 <C++ Source> modules\jolt_physics\jolt_physics_server_3d.cpp:1776 @ pin_joint_get_applied_force()

is being given when node_a and node_b is empty while trying to get applied forces. This is pretty simple to work around, but in my opinion it shouldn't be giving errors for this. Loving the commit so far though 😘

As far as i understand the jolt things, this is how it is supposed to throw errors when some data is missing. The code should run properly however, it just return 0.0 and log that error. This errors appear in other jolt functions as well. I've implemented the error checks the same way.

@PiCode9560

Copy link
Copy Markdown
Contributor

Would it be possible to change the functions to return a vector3 version of the force/torque, instead of the magnitude? I need it to make a breakable joint that only breaks in specific direction.

@brainfoolong

Copy link
Copy Markdown
Author

Would it be possible to change the functions to return a vector3 version of the force/torque, instead of the magnitude? I need it to make a breakable joint that only breaks in specific direction.

Not with Jolt. Jolt exposes this as it is now. It's not a problem of this PR, it exposes all this as it is originally from the physics engine.

You may have to go to the jolt library to suggest it there, but i don't think that this is a thing that can be changed without rewriting the whole engine.

@PiCode9560

PiCode9560 commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

It looks like jolt already exposed it. It is just that godot is the one that exposed it as a magnetude:
https://github.com/jrouwe/JoltPhysics/blob/83eea75749660afb8c654541274079ff2bbb11b3/Jolt/Physics/Constraints/HingeConstraint.h#L143
https://github.com/godotengine/godot/blob/2d53a62898a65ba635efd554b101e033070c784c/modules/jolt_physics/joints/jolt_pin_joint_3d.cpp#L134C21-L134C43

If the method is not used anywhere, should we just change it to return the vector3 force instead? 🤔

@brainfoolong

Copy link
Copy Markdown
Author

It looks like jolt already exposed it. It is just that godot is the one that exposed it as a magnetude: https://github.com/jrouwe/JoltPhysics/blob/83eea75749660afb8c654541274079ff2bbb11b3/Jolt/Physics/Constraints/HingeConstraint.h#L143 https://github.com/godotengine/godot/blob/2d53a62898a65ba635efd554b101e033070c784c/modules/jolt_physics/joints/jolt_pin_joint_3d.cpp#L134C21-L134C43

If the method is not used anywhere, should we just change it to return the vector3 force instead? 🤔

Ah, i see, you are right. Interesting. Well, that shifts the problem to godot, but still not for this PR. To keep it on-topic, you should create a new Feature request about that.

@jrouwe

jrouwe commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

If I remember correctly: The reason that only the magnitude was exposed is that these quantities are in constraint space and there currently isn't a way to know what that is in Godot.

@PiCode9560

Copy link
Copy Markdown
Contributor

If I remember correctly: The reason that only the magnitude was exposed is that these quantities are in constraint space and there currently isn't a way to know what that is in Godot.

Can it be returned in world space instead?

@jrouwe

jrouwe commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Can it be returned in world space instead?

You can, but it gives you a dilemma:

  • Do you return it in world space of the current joint position/orientation (which means after the joint has moved, joints are first evaluated and then the simulation is stepped)
  • Do you return it in world space when the joint was evaluated (which means you cannot go back to local space as the joint has moved)

@Repiteo Repiteo requested a review from mihe February 11, 2026 15:18
@Repiteo Repiteo requested a review from a team as a code owner February 17, 2026 20:10
@brainfoolong

brainfoolong commented May 18, 2026

Copy link
Copy Markdown
Author

I will close this PR at the end of may 2026. My spare time shifted and a cannot provide any more support for this PR.
I guess in the current state it's even not mergable because to much time without any action has been passed and main code has been drifted away.

Hope someone can bring life to this or close it right away, i'm fine with both.

Greetz

@AThousandShips

Copy link
Copy Markdown
Member

I don't think there's any issues with merging this currently, at least there aren't any merge conflicts, and it's unlikely that it's become so out of date in so short a time

This is unlikely to be merged before the end of the month as 4.7 is likely to release no earlier than the end of the month, though this could get in early 4.8 if it is ready

@almic

almic commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Would you combine all the commits into one?

EDIT: also, I think the generic 6dof methods should be placed just above _configure_joint() so it matches all the other method orderings. right now it is between get_param_z() and set_flag_z() methods.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose Jolt Joint3D "get_applied_force" and "get_applied_torque"

9 participants